Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 2 | /* |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 3 | * Copyright (C) 2009 Wolfram Sang, Pengutronix |
| 4 | * |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 5 | * Check max730x.c for further details. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/platform_device.h> |
| 11 | #include <linux/mutex.h> |
| 12 | #include <linux/i2c.h> |
| 13 | #include <linux/spi/max7301.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 15 | |
| 16 | static int max7300_i2c_write(struct device *dev, unsigned int reg, |
| 17 | unsigned int val) |
| 18 | { |
| 19 | struct i2c_client *client = to_i2c_client(dev); |
| 20 | |
| 21 | return i2c_smbus_write_byte_data(client, reg, val); |
| 22 | } |
| 23 | |
| 24 | static int max7300_i2c_read(struct device *dev, unsigned int reg) |
| 25 | { |
| 26 | struct i2c_client *client = to_i2c_client(dev); |
| 27 | |
| 28 | return i2c_smbus_read_byte_data(client, reg); |
| 29 | } |
| 30 | |
Bill Pemberton | 3836309 | 2012-11-19 13:22:34 -0500 | [diff] [blame] | 31 | static int max7300_probe(struct i2c_client *client, |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 32 | const struct i2c_device_id *id) |
| 33 | { |
| 34 | struct max7301 *ts; |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 35 | |
| 36 | if (!i2c_check_functionality(client->adapter, |
| 37 | I2C_FUNC_SMBUS_BYTE_DATA)) |
| 38 | return -EIO; |
| 39 | |
Jingoo Han | c3fe2bf | 2013-03-15 18:14:46 +0900 | [diff] [blame] | 40 | ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL); |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 41 | if (!ts) |
| 42 | return -ENOMEM; |
| 43 | |
| 44 | ts->read = max7300_i2c_read; |
| 45 | ts->write = max7300_i2c_write; |
| 46 | ts->dev = &client->dev; |
| 47 | |
Varka Bhadram | 76a2dae | 2015-03-31 09:49:09 +0530 | [diff] [blame] | 48 | return __max730x_probe(ts); |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Bill Pemberton | 206210c | 2012-11-19 13:25:50 -0500 | [diff] [blame] | 51 | static int max7300_remove(struct i2c_client *client) |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 52 | { |
| 53 | return __max730x_remove(&client->dev); |
| 54 | } |
| 55 | |
| 56 | static const struct i2c_device_id max7300_id[] = { |
| 57 | { "max7300", 0 }, |
| 58 | { } |
| 59 | }; |
| 60 | MODULE_DEVICE_TABLE(i2c, max7300_id); |
| 61 | |
| 62 | static struct i2c_driver max7300_driver = { |
| 63 | .driver = { |
| 64 | .name = "max7300", |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 65 | }, |
| 66 | .probe = max7300_probe, |
Bill Pemberton | 8283c4f | 2012-11-19 13:20:08 -0500 | [diff] [blame] | 67 | .remove = max7300_remove, |
Wolfram Sang | e952805 | 2010-03-05 13:44:33 -0800 | [diff] [blame] | 68 | .id_table = max7300_id, |
| 69 | }; |
| 70 | |
| 71 | static int __init max7300_init(void) |
| 72 | { |
| 73 | return i2c_add_driver(&max7300_driver); |
| 74 | } |
| 75 | subsys_initcall(max7300_init); |
| 76 | |
| 77 | static void __exit max7300_exit(void) |
| 78 | { |
| 79 | i2c_del_driver(&max7300_driver); |
| 80 | } |
| 81 | module_exit(max7300_exit); |
| 82 | |
| 83 | MODULE_AUTHOR("Wolfram Sang"); |
| 84 | MODULE_LICENSE("GPL v2"); |
| 85 | MODULE_DESCRIPTION("MAX7300 GPIO-Expander"); |