15 #include <linux/kernel.h>
16 #include <linux/module.h>
19 #include <linux/i2c.h>
21 #include <linux/slab.h>
23 #define DA9030_CHIP_ID 0x00
24 #define DA9030_EVENT_A 0x01
25 #define DA9030_EVENT_B 0x02
26 #define DA9030_EVENT_C 0x03
27 #define DA9030_STATUS 0x04
28 #define DA9030_IRQ_MASK_A 0x05
29 #define DA9030_IRQ_MASK_B 0x06
30 #define DA9030_IRQ_MASK_C 0x07
31 #define DA9030_SYS_CTRL_A 0x08
32 #define DA9030_SYS_CTRL_B 0x09
33 #define DA9030_FAULT_LOG 0x0a
35 #define DA9034_CHIP_ID 0x00
36 #define DA9034_EVENT_A 0x01
37 #define DA9034_EVENT_B 0x02
38 #define DA9034_EVENT_C 0x03
39 #define DA9034_EVENT_D 0x04
40 #define DA9034_STATUS_A 0x05
41 #define DA9034_STATUS_B 0x06
42 #define DA9034_IRQ_MASK_A 0x07
43 #define DA9034_IRQ_MASK_B 0x08
44 #define DA9034_IRQ_MASK_C 0x09
45 #define DA9034_IRQ_MASK_D 0x0a
46 #define DA9034_SYS_CTRL_A 0x0b
47 #define DA9034_SYS_CTRL_B 0x0c
48 #define DA9034_FAULT_LOG 0x0d
81 dev_err(&client->
dev,
"failed reading at 0x%02x\n", reg);
89 static inline int __da903x_reads(
struct i2c_client *client,
int reg,
96 dev_err(&client->
dev,
"failed reading from 0x%02x\n", reg);
102 static inline int __da903x_write(
struct i2c_client *client,
109 dev_err(&client->
dev,
"failed writing 0x%02x to 0x%02x\n",
116 static inline int __da903x_writes(
struct i2c_client *client,
int reg,
123 dev_err(&client->
dev,
"failed writings to 0x%02x\n", reg);
134 chip->
ops->unmask_events(chip, events);
144 chip->
ops->mask_events(chip, events);
181 ret = __da903x_read(chip->
client, reg, ®_val);
185 if ((reg_val & bit_mask) != bit_mask) {
187 ret = __da903x_write(chip->
client, reg, reg_val);
203 ret = __da903x_read(chip->
client, reg, ®_val);
207 if (reg_val & bit_mask) {
208 reg_val &= ~bit_mask;
209 ret = __da903x_write(chip->
client, reg, reg_val);
225 ret = __da903x_read(chip->
client, reg, ®_val);
229 if ((reg_val & mask) != val) {
230 reg_val = (reg_val & ~mask) | val;
231 ret = __da903x_write(chip->
client, reg, reg_val);
244 chip->
ops->read_status(chip, &status);
245 return ((status & sbits) == sbits);
262 dev_info(chip->
dev,
"DA9030 (CHIP ID: 0x%02x) detected\n", chip_id);
301 *events = (v[2] << 16) | (v[1] << 8) | v[0];
310 static int da9034_init_chip(
struct da903x_chip *chip)
324 __da903x_write(chip->
client, 0x10, 0x07);
325 __da903x_write(chip->
client, 0x11, 0xff);
326 __da903x_write(chip->
client, 0x12, 0xff);
333 __da903x_write(chip->
client, 0x90, 0x01);
334 __da903x_write(chip->
client, 0xB0, 0x08);
337 __da903x_write(chip->
client, 0x20, 0x00);
339 dev_info(chip->
dev,
"DA9034 (CHIP ID: 0x%02x) detected\n", chip_id);
343 static int da9034_unmask_events(
struct da903x_chip *chip,
unsigned int events)
357 static int da9034_mask_events(
struct da903x_chip *chip,
unsigned int events)
371 static int da9034_read_events(
struct da903x_chip *chip,
unsigned int *events)
380 *events = (v[3] << 24) | (v[2] << 16) | (v[1] << 8) | v[0];
393 *status = (v[1] << 8) | v[0];
401 unsigned int events = 0;
404 if (chip->
ops->read_events(chip, &events))
429 .init_chip = da9030_init_chip,
430 .unmask_events = da9030_unmask_events,
431 .mask_events = da9030_mask_events,
432 .read_events = da9030_read_events,
433 .read_status = da9030_read_status,
436 .init_chip = da9034_init_chip,
437 .unmask_events = da9034_unmask_events,
438 .mask_events = da9034_mask_events,
439 .read_events = da9034_read_events,
440 .read_status = da9034_read_status,
457 static int da903x_remove_subdevs(
struct da903x_chip *chip)
478 pdev->
dev.parent = chip->
dev;
490 da903x_remove_subdevs(chip);
508 chip->
ops = &da903x_ops[
id->driver_data];
514 i2c_set_clientdata(client, chip);
516 ret = chip->
ops->init_chip(chip);
523 chip->
ops->read_events(chip, &tmp);
529 dev_err(&client->
dev,
"failed to request irq %d\n",
534 ret = da903x_add_subdevs(chip, pdata);
549 struct da903x_chip *chip = i2c_get_clientdata(client);
551 da903x_remove_subdevs(chip);
562 .probe = da903x_probe,
564 .id_table = da903x_id_table,
567 static int __init da903x_init(
void)
569 return i2c_add_driver(&da903x_driver);
573 static void __exit da903x_exit(
void)