4 * Copyright(c) 2009 Dialog Semiconductor Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef __LINUX_MFD_DA9052_DA9052_H
23 #define __LINUX_MFD_DA9052_DA9052_H
25 #include <linux/slab.h>
26 #include <linux/mfd/core.h>
28 #include <linux/mfd/da9052/eh.h>
29 #include <linux/mfd/da9052/reg.h>
30 #include <linux/mfd/da9052/led.h>
36 #define DA9052_SSC_DEVICE_NAME "da9052_ssc"
37 #define DA9052_EH_DEVICE_NAME "da9052_eh"
39 #define DA9052_IRQ S3C_EINT(9)
41 /* Module specific error codes */
42 #define INVALID_REGISTER 2
43 #define INVALID_READ 3
44 #define INVALID_PAGE 4
46 /* Defines for Volatile and Non Volatile register types */
48 #define NON_VOLATILE 1
50 /* Defines for cache state */
54 /* Total number of registers in DA9057 */
55 #define DA9052_REG_CNT DA9052_PAGE1_REG_END
57 /* Maximum number of registers that can be read/written by a singe request */
58 #define MAX_READ_WRITE_CNT 16
61 #define DA9052_SSC_SPI_DEVICE_NAME "da9052_ssc_spi"
62 #define PAGE_0_START 1
63 #define PAGE_0_END 127
64 #define PAGE_1_START 128
65 #define PAGE_1_END 255
66 #define ACTIVE_PAGE_0 0
67 #define ACTIVE_PAGE_1 1
69 #define PAGECON_128 128
72 #define DA9052_SSC_I2C_DEVICE_NAME "da9052_ssc_i2c"
73 #define DA9052_I2C_ADDR 0x90
74 #define DA9052_SSC_I2C_PAGE_WRITE_MODE 0
75 #define DA9052_SSC_I2C_REPEAT_WRITE_MODE 1
76 #define DA9052_SSC_I2C_WRITE_MODE DA9052_SSC_I2C_REPEAT_WRITE_MODE
78 struct da9052_ssc_msg {
83 struct ssc_cache_entry{
86 unsigned char status:4;
90 struct list_head nb_list;
91 unsigned char eve_type;
92 void (*call_back)(struct da9052_eh_nb *, unsigned int);
95 struct da9052_regulator_init_data {
96 struct regulator_init_data *init_data;
99 struct da9052_regulator_platform_data {
100 struct regulator_init_data *regulators;
103 struct da9052_tsi_platform_data {
105 u16 tsi_delay_bit_shift;
106 u16 tsi_skip_bit_shift;
107 u16 num_gpio_tsi_register;
108 u16 tsi_supply_voltage;
111 u16 max_tsi_skip_slot;
116 struct mutex ssc_lock;
117 struct mutex eve_nb_lock;
118 struct mutex manconv_lock;
119 struct work_struct eh_isr_work;
120 struct ssc_cache_entry ssc_cache[DA9052_REG_CNT];
121 int (*read) (struct da9052 *da9052, struct da9052_ssc_msg *sscmsg);
122 int (*write) (struct da9052 *da9052, struct da9052_ssc_msg *sscmsg);
123 int (*read_many) (struct da9052 *da9052,
124 struct da9052_ssc_msg *sscmsg, int cnt);
125 int (*write_many)(struct da9052 *da9052,
126 struct da9052_ssc_msg *sscmsg, int cnt);
127 int (*register_event_notifier)(struct da9052 *da9052,
128 struct da9052_eh_nb *nb);
129 int (*unregister_event_notifier)(struct da9052 *da9052,
130 struct da9052_eh_nb *nb);
132 int connecting_device;
133 struct spi_device *spi_dev;
134 unsigned int spi_active_page;
135 unsigned char rw_pol;
136 unsigned char *spi_rx_buf;
137 unsigned char *spi_tx_buf;
139 struct i2c_client *i2c_client;
141 struct i2c_adapter *adapter;
142 unsigned char slave_addr;
146 struct da9052_platform_data {
147 int (*init)(struct da9052 *da9052);
152 struct da9052 *da9052;
153 struct regulator_init_data *regulators;
154 struct da9052_leds_platform_data *led_data;
155 struct da9052_tsi_platform_data *tsi_data;
158 struct da9052_ssc_ops {
159 int (*write)(struct da9052 *da9052, struct da9052_ssc_msg *msg);
160 int (*read)(struct da9052 *da9052, struct da9052_ssc_msg *msg);
161 int (*write_many)(struct da9052 *da9052,
162 struct da9052_ssc_msg *sscmsg, int msg_no);
163 int (*read_many)(struct da9052 *da9052,
164 struct da9052_ssc_msg *sscmsg, int msg_no);
165 int (*device_register)(struct da9052 *da9052);
166 void (*device_unregister)(void);
169 int da9052_ssc_write(struct da9052 *da9052,
170 struct da9052_ssc_msg *sscmsg);
171 int da9052_ssc_read(struct da9052 *da9052,
172 struct da9052_ssc_msg *sscmsg);
173 int da9052_ssc_write_many(struct da9052 *da9052,
174 struct da9052_ssc_msg *sscmsg, int cnt);
175 int da9052_ssc_read_many(struct da9052 *da9052,
176 struct da9052_ssc_msg *sscmsg, int cnt);
178 int da9052_spi_write(struct da9052 *da9052,
179 struct da9052_ssc_msg *msg);
180 int da9052_spi_read(struct da9052 *da9052,
181 struct da9052_ssc_msg *msg);
183 int da9052_spi_write_many(struct da9052 *da9052, struct da9052_ssc_msg *sscmsg,
185 int da9052_spi_read_many(struct da9052 *da9052,
186 struct da9052_ssc_msg *sscmsg,
189 void da9052_ssc_exit(struct da9052 *da9052);
190 int da9052_ssc_init(struct da9052 *da9052);
192 /* I2C specific Functions */
193 int da9052_i2c_write(struct da9052 *da9052, struct da9052_ssc_msg *msg);
194 int da9052_i2c_read(struct da9052 *da9052, struct da9052_ssc_msg *msg);
195 int da9052_i2c_write_many(struct da9052 *da9052,
196 struct da9052_ssc_msg *sscmsg, int msg_no);
197 int da9052_i2c_read_many(struct da9052 *da9052,
198 struct da9052_ssc_msg *sscmsg, int msg_no);
200 void da9052_lock(struct da9052 *da9052);
201 void da9052_unlock(struct da9052 *da9052);
202 int eh_register_nb(struct da9052 *da9052, struct da9052_eh_nb *nb);
203 int eh_unregister_nb(struct da9052 *da9052, struct da9052_eh_nb *nb);
204 int da9052_manual_read(struct da9052 *da9052,
205 unsigned char channel);
206 #endif /* __LINUX_MFD_DA9052_DA9052_H */