Merge tag 'led-fixes-for-v4.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / gpio / gpio-max7300.c
CommitLineData
e952805d 1/*
e952805d
WS
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>
5a0e3ad6 17#include <linux/slab.h>
e952805d
WS
18
19static 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
27static 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
3836309d 34static int max7300_probe(struct i2c_client *client,
e952805d
WS
35 const struct i2c_device_id *id)
36{
37 struct max7301 *ts;
e952805d
WS
38
39 if (!i2c_check_functionality(client->adapter,
40 I2C_FUNC_SMBUS_BYTE_DATA))
41 return -EIO;
42
c3fe2bf4 43 ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
e952805d
WS
44 if (!ts)
45 return -ENOMEM;
46
47 ts->read = max7300_i2c_read;
48 ts->write = max7300_i2c_write;
49 ts->dev = &client->dev;
50
76a2dae0 51 return __max730x_probe(ts);
e952805d
WS
52}
53
206210ce 54static int max7300_remove(struct i2c_client *client)
e952805d
WS
55{
56 return __max730x_remove(&client->dev);
57}
58
59static const struct i2c_device_id max7300_id[] = {
60 { "max7300", 0 },
61 { }
62};
63MODULE_DEVICE_TABLE(i2c, max7300_id);
64
65static struct i2c_driver max7300_driver = {
66 .driver = {
67 .name = "max7300",
68 .owner = THIS_MODULE,
69 },
70 .probe = max7300_probe,
8283c4ff 71 .remove = max7300_remove,
e952805d
WS
72 .id_table = max7300_id,
73};
74
75static int __init max7300_init(void)
76{
77 return i2c_add_driver(&max7300_driver);
78}
79subsys_initcall(max7300_init);
80
81static void __exit max7300_exit(void)
82{
83 i2c_del_driver(&max7300_driver);
84}
85module_exit(max7300_exit);
86
87MODULE_AUTHOR("Wolfram Sang");
88MODULE_LICENSE("GPL v2");
89MODULE_DESCRIPTION("MAX7300 GPIO-Expander");
This page took 0.51768 seconds and 5 git commands to generate.