Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
e952805d | 2 | /* |
e952805d WS |
3 | * Copyright (C) 2009 Wolfram Sang, Pengutronix |
4 | * | |
e952805d WS |
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> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
e952805d WS |
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 | ||
bf08ce13 | 31 | static int max7300_probe(struct i2c_client *client) |
e952805d WS |
32 | { |
33 | struct max7301 *ts; | |
e952805d WS |
34 | |
35 | if (!i2c_check_functionality(client->adapter, | |
36 | I2C_FUNC_SMBUS_BYTE_DATA)) | |
37 | return -EIO; | |
38 | ||
c3fe2bf4 | 39 | ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL); |
e952805d WS |
40 | if (!ts) |
41 | return -ENOMEM; | |
42 | ||
43 | ts->read = max7300_i2c_read; | |
44 | ts->write = max7300_i2c_write; | |
45 | ts->dev = &client->dev; | |
46 | ||
76a2dae0 | 47 | return __max730x_probe(ts); |
e952805d WS |
48 | } |
49 | ||
ed5c2f5f | 50 | static void max7300_remove(struct i2c_client *client) |
e952805d | 51 | { |
06de2cd7 | 52 | __max730x_remove(&client->dev); |
e952805d WS |
53 | } |
54 | ||
55 | static const struct i2c_device_id max7300_id[] = { | |
56 | { "max7300", 0 }, | |
57 | { } | |
58 | }; | |
59 | MODULE_DEVICE_TABLE(i2c, max7300_id); | |
60 | ||
61 | static struct i2c_driver max7300_driver = { | |
62 | .driver = { | |
63 | .name = "max7300", | |
e952805d | 64 | }, |
bf08ce13 | 65 | .probe_new = max7300_probe, |
8283c4ff | 66 | .remove = max7300_remove, |
e952805d WS |
67 | .id_table = max7300_id, |
68 | }; | |
69 | ||
70 | static int __init max7300_init(void) | |
71 | { | |
72 | return i2c_add_driver(&max7300_driver); | |
73 | } | |
74 | subsys_initcall(max7300_init); | |
75 | ||
76 | static void __exit max7300_exit(void) | |
77 | { | |
78 | i2c_del_driver(&max7300_driver); | |
79 | } | |
80 | module_exit(max7300_exit); | |
81 | ||
82 | MODULE_AUTHOR("Wolfram Sang"); | |
83 | MODULE_LICENSE("GPL v2"); | |
84 | MODULE_DESCRIPTION("MAX7300 GPIO-Expander"); |