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