1 /* da9063-i2c.c: Interrupt support for Dialog DA9063
3 * Copyright 2012 Dialog Semiconductor Ltd.
4 * Copyright 2013 Philipp Zabel, Pengutronix
6 * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/i2c.h>
18 #include <linux/regmap.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/err.h>
23 #include <linux/mfd/core.h>
24 #include <linux/mfd/da9063/core.h>
25 #include <linux/mfd/da9063/pdata.h>
26 #include <linux/mfd/da9063/registers.h>
28 static const struct regmap_range da9063_readable_ranges
[] = {
30 .range_min
= DA9063_REG_PAGE_CON
,
31 .range_max
= DA9063_REG_SECOND_D
,
33 .range_min
= DA9063_REG_SEQ
,
34 .range_max
= DA9063_REG_ID_32_31
,
36 .range_min
= DA9063_REG_SEQ_A
,
37 .range_max
= DA9063_REG_AUTO3_LOW
,
39 .range_min
= DA9063_REG_T_OFFSET
,
40 .range_max
= DA9063_REG_GP_ID_19
,
42 .range_min
= DA9063_REG_CHIP_ID
,
43 .range_max
= DA9063_REG_CHIP_VARIANT
,
47 static const struct regmap_range da9063_writeable_ranges
[] = {
49 .range_min
= DA9063_REG_PAGE_CON
,
50 .range_max
= DA9063_REG_PAGE_CON
,
52 .range_min
= DA9063_REG_FAULT_LOG
,
53 .range_max
= DA9063_REG_VSYS_MON
,
55 .range_min
= DA9063_REG_COUNT_S
,
56 .range_max
= DA9063_REG_ALARM_Y
,
58 .range_min
= DA9063_REG_SEQ
,
59 .range_max
= DA9063_REG_ID_32_31
,
61 .range_min
= DA9063_REG_SEQ_A
,
62 .range_max
= DA9063_REG_AUTO3_LOW
,
64 .range_min
= DA9063_REG_CONFIG_I
,
65 .range_max
= DA9063_REG_MON_REG_4
,
67 .range_min
= DA9063_REG_GP_ID_0
,
68 .range_max
= DA9063_REG_GP_ID_19
,
72 static const struct regmap_range da9063_volatile_ranges
[] = {
74 .range_min
= DA9063_REG_STATUS_A
,
75 .range_max
= DA9063_REG_EVENT_D
,
77 .range_min
= DA9063_REG_CONTROL_F
,
78 .range_max
= DA9063_REG_CONTROL_F
,
80 .range_min
= DA9063_REG_ADC_MAN
,
81 .range_max
= DA9063_REG_ADC_MAN
,
83 .range_min
= DA9063_REG_ADC_RES_L
,
84 .range_max
= DA9063_REG_SECOND_D
,
86 .range_min
= DA9063_REG_MON_REG_5
,
87 .range_max
= DA9063_REG_MON_REG_6
,
91 static const struct regmap_access_table da9063_readable_table
= {
92 .yes_ranges
= da9063_readable_ranges
,
93 .n_yes_ranges
= ARRAY_SIZE(da9063_readable_ranges
),
96 static const struct regmap_access_table da9063_writeable_table
= {
97 .yes_ranges
= da9063_writeable_ranges
,
98 .n_yes_ranges
= ARRAY_SIZE(da9063_writeable_ranges
),
101 static const struct regmap_access_table da9063_volatile_table
= {
102 .yes_ranges
= da9063_volatile_ranges
,
103 .n_yes_ranges
= ARRAY_SIZE(da9063_volatile_ranges
),
106 static const struct regmap_range_cfg da9063_range_cfg
[] = {
108 .range_min
= DA9063_REG_PAGE_CON
,
109 .range_max
= DA9063_REG_CHIP_VARIANT
,
110 .selector_reg
= DA9063_REG_PAGE_CON
,
111 .selector_mask
= 1 << DA9063_I2C_PAGE_SEL_SHIFT
,
112 .selector_shift
= DA9063_I2C_PAGE_SEL_SHIFT
,
118 static struct regmap_config da9063_regmap_config
= {
121 .ranges
= da9063_range_cfg
,
122 .num_ranges
= ARRAY_SIZE(da9063_range_cfg
),
123 .max_register
= DA9063_REG_CHIP_VARIANT
,
125 .cache_type
= REGCACHE_RBTREE
,
127 .rd_table
= &da9063_readable_table
,
128 .wr_table
= &da9063_writeable_table
,
129 .volatile_table
= &da9063_volatile_table
,
132 static int da9063_i2c_probe(struct i2c_client
*i2c
,
133 const struct i2c_device_id
*id
)
135 struct da9063
*da9063
;
138 da9063
= devm_kzalloc(&i2c
->dev
, sizeof(struct da9063
), GFP_KERNEL
);
142 i2c_set_clientdata(i2c
, da9063
);
143 da9063
->dev
= &i2c
->dev
;
144 da9063
->chip_irq
= i2c
->irq
;
146 da9063
->regmap
= devm_regmap_init_i2c(i2c
, &da9063_regmap_config
);
147 if (IS_ERR(da9063
->regmap
)) {
148 ret
= PTR_ERR(da9063
->regmap
);
149 dev_err(da9063
->dev
, "Failed to allocate register map: %d\n",
154 return da9063_device_init(da9063
, i2c
->irq
);
157 static int da9063_i2c_remove(struct i2c_client
*i2c
)
159 struct da9063
*da9063
= i2c_get_clientdata(i2c
);
161 da9063_device_exit(da9063
);
166 static const struct i2c_device_id da9063_i2c_id
[] = {
167 {"da9063", PMIC_DA9063
},
170 MODULE_DEVICE_TABLE(i2c
, da9063_i2c_id
);
172 static struct i2c_driver da9063_i2c_driver
= {
175 .owner
= THIS_MODULE
,
177 .probe
= da9063_i2c_probe
,
178 .remove
= da9063_i2c_remove
,
179 .id_table
= da9063_i2c_id
,
182 module_i2c_driver(da9063_i2c_driver
);