forked from savoca/mcp9808
/
minnow.c
58 lines (46 loc) · 1.41 KB
/
minnow.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
* Copyright (c) 2015, Alex Deddo <adeddo27@gmail.com>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) "%s: " fmt, __func__
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#define DEV_NAME "mcp9808"
#define DEV_ADDR 0x18
#define GPIO_IRQ 0x152
static struct i2c_adapter *adap;
static struct i2c_board_info board_info[] __initdata = {
{
I2C_BOARD_INFO(DEV_NAME, DEV_ADDR),
.irq = GPIO_IRQ,
},
};
static struct i2c_client *client;
static int __init minnow_module_init(void)
{
adap = i2c_get_adapter(7);
client = i2c_new_device(adap, board_info);
pr_info("initialized\n");
return 0;
}
static void __exit minnow_module_exit(void)
{
i2c_unregister_device(client);
i2c_put_adapter(adap);
pr_info("exited\n");
}
module_init(minnow_module_init);
module_exit(minnow_module_exit);
MODULE_AUTHOR("Alex Deddo");
MODULE_DESCRIPTION("MinnowMax I2C device initializer");
MODULE_LICENSE("GPL");