18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2009 Wolfram Sang, Pengutronix 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Check max730x.c for further details. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/module.h> 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 118c2ecf20Sopenharmony_ci#include <linux/mutex.h> 128c2ecf20Sopenharmony_ci#include <linux/i2c.h> 138c2ecf20Sopenharmony_ci#include <linux/spi/max7301.h> 148c2ecf20Sopenharmony_ci#include <linux/slab.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistatic int max7300_i2c_write(struct device *dev, unsigned int reg, 178c2ecf20Sopenharmony_ci unsigned int val) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci return i2c_smbus_write_byte_data(client, reg, val); 228c2ecf20Sopenharmony_ci} 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic int max7300_i2c_read(struct device *dev, unsigned int reg) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci return i2c_smbus_read_byte_data(client, reg); 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic int max7300_probe(struct i2c_client *client, 328c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci struct max7301 *ts; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci if (!i2c_check_functionality(client->adapter, 378c2ecf20Sopenharmony_ci I2C_FUNC_SMBUS_BYTE_DATA)) 388c2ecf20Sopenharmony_ci return -EIO; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL); 418c2ecf20Sopenharmony_ci if (!ts) 428c2ecf20Sopenharmony_ci return -ENOMEM; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci ts->read = max7300_i2c_read; 458c2ecf20Sopenharmony_ci ts->write = max7300_i2c_write; 468c2ecf20Sopenharmony_ci ts->dev = &client->dev; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci return __max730x_probe(ts); 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic int max7300_remove(struct i2c_client *client) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci return __max730x_remove(&client->dev); 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic const struct i2c_device_id max7300_id[] = { 578c2ecf20Sopenharmony_ci { "max7300", 0 }, 588c2ecf20Sopenharmony_ci { } 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, max7300_id); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic struct i2c_driver max7300_driver = { 638c2ecf20Sopenharmony_ci .driver = { 648c2ecf20Sopenharmony_ci .name = "max7300", 658c2ecf20Sopenharmony_ci }, 668c2ecf20Sopenharmony_ci .probe = max7300_probe, 678c2ecf20Sopenharmony_ci .remove = max7300_remove, 688c2ecf20Sopenharmony_ci .id_table = max7300_id, 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic int __init max7300_init(void) 728c2ecf20Sopenharmony_ci{ 738c2ecf20Sopenharmony_ci return i2c_add_driver(&max7300_driver); 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_cisubsys_initcall(max7300_init); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic void __exit max7300_exit(void) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci i2c_del_driver(&max7300_driver); 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_cimodule_exit(max7300_exit); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciMODULE_AUTHOR("Wolfram Sang"); 848c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 858c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MAX7300 GPIO-Expander"); 86