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