2 * I2C bus driver for ADT7316/7/8 ADT7516/7/9 digital temperature
5 * Copyright 2010 Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/i2c.h>
13 #include <linux/interrupt.h>
14 #include <linux/module.h>
19 * adt7316 register access by I2C
21 static int adt7316_i2c_read(void *client
, u8 reg
, u8
*data
)
23 struct i2c_client
*cl
= client
;
26 ret
= i2c_smbus_write_byte(cl
, reg
);
28 dev_err(&cl
->dev
, "I2C fail to select reg\n");
32 ret
= i2c_smbus_read_byte(client
);
34 dev_err(&cl
->dev
, "I2C read error\n");
41 static int adt7316_i2c_write(void *client
, u8 reg
, u8 data
)
43 struct i2c_client
*cl
= client
;
46 ret
= i2c_smbus_write_byte_data(cl
, reg
, data
);
48 dev_err(&cl
->dev
, "I2C write error\n");
53 static int adt7316_i2c_multi_read(void *client
, u8 reg
, u8 count
, u8
*data
)
55 struct i2c_client
*cl
= client
;
58 if (count
> ADT7316_REG_MAX_ADDR
)
59 count
= ADT7316_REG_MAX_ADDR
;
61 for (i
= 0; i
< count
; i
++) {
62 ret
= adt7316_i2c_read(cl
, reg
, &data
[i
]);
64 dev_err(&cl
->dev
, "I2C multi read error\n");
72 static int adt7316_i2c_multi_write(void *client
, u8 reg
, u8 count
, u8
*data
)
74 struct i2c_client
*cl
= client
;
77 if (count
> ADT7316_REG_MAX_ADDR
)
78 count
= ADT7316_REG_MAX_ADDR
;
80 for (i
= 0; i
< count
; i
++) {
81 ret
= adt7316_i2c_write(cl
, reg
, data
[i
]);
83 dev_err(&cl
->dev
, "I2C multi write error\n");
92 * device probe and remove
95 static int __devinit
adt7316_i2c_probe(struct i2c_client
*client
,
96 const struct i2c_device_id
*id
)
98 struct adt7316_bus bus
= {
101 .irq_flags
= IRQF_TRIGGER_LOW
,
102 .read
= adt7316_i2c_read
,
103 .write
= adt7316_i2c_write
,
104 .multi_read
= adt7316_i2c_multi_read
,
105 .multi_write
= adt7316_i2c_multi_write
,
108 return adt7316_probe(&client
->dev
, &bus
, id
->name
);
111 static int __devexit
adt7316_i2c_remove(struct i2c_client
*client
)
113 return adt7316_remove(&client
->dev
);
116 static const struct i2c_device_id adt7316_i2c_id
[] = {
126 MODULE_DEVICE_TABLE(i2c
, adt7316_i2c_id
);
129 static int adt7316_i2c_suspend(struct i2c_client
*client
, pm_message_t message
)
131 return adt7316_disable(&client
->dev
);
134 static int adt7316_i2c_resume(struct i2c_client
*client
)
136 return adt7316_enable(&client
->dev
);
139 # define adt7316_i2c_suspend NULL
140 # define adt7316_i2c_resume NULL
143 static struct i2c_driver adt7316_driver
= {
146 .owner
= THIS_MODULE
,
148 .probe
= adt7316_i2c_probe
,
149 .remove
= __devexit_p(adt7316_i2c_remove
),
150 .suspend
= adt7316_i2c_suspend
,
151 .resume
= adt7316_i2c_resume
,
152 .id_table
= adt7316_i2c_id
,
154 module_i2c_driver(adt7316_driver
);
156 MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
157 MODULE_DESCRIPTION("I2C bus driver for Analog Devices ADT7316/7/9 and"
158 "ADT7516/7/8 digital temperature sensor, ADC and DAC");
159 MODULE_LICENSE("GPL v2");