Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __MFD_TABLA_CORE_H__ |
| 14 | #define __MFD_TABLA_CORE_H__ |
| 15 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 16 | #include <linux/types.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 18 | #include <linux/pm_qos.h> |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/of_irq.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 21 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 22 | #define WCD9XXX_NUM_IRQ_REGS 4 |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 23 | |
| 24 | #define WCD9XXX_SLIM_NUM_PORT_REG 3 |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 25 | #define TABLA_VERSION_1_0 0 |
| 26 | #define TABLA_VERSION_1_1 1 |
| 27 | #define TABLA_VERSION_2_0 2 |
| 28 | #define TABLA_IS_1_X(ver) \ |
| 29 | (((ver == TABLA_VERSION_1_0) || (ver == TABLA_VERSION_1_1)) ? 1 : 0) |
| 30 | #define TABLA_IS_2_0(ver) ((ver == TABLA_VERSION_2_0) ? 1 : 0) |
| 31 | |
Bhalchandra Gajare | 87fef4c | 2013-02-19 14:57:03 -0800 | [diff] [blame] | 32 | #define WCD9XXX_SUPPLY_BUCK_NAME "cdc-vdd-buck" |
| 33 | |
Bhalchandra Gajare | 83c81f6 | 2012-05-18 16:09:05 -0700 | [diff] [blame] | 34 | #define SITAR_VERSION_1P0 0 |
| 35 | #define SITAR_VERSION_1P1 1 |
| 36 | #define SITAR_IS_1P0(ver) \ |
| 37 | ((ver == SITAR_VERSION_1P0) ? 1 : 0) |
| 38 | #define SITAR_IS_1P1(ver) \ |
| 39 | ((ver == SITAR_VERSION_1P1) ? 1 : 0) |
| 40 | |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 41 | #define TAIKO_VERSION_1_0 1 |
Kiran Kandi | 7b7d2ff | 2012-09-14 14:52:14 -0700 | [diff] [blame] | 42 | #define TAIKO_IS_1_0(ver) \ |
| 43 | ((ver == TAIKO_VERSION_1_0) ? 1 : 0) |
| 44 | |
Bhalchandra Gajare | 750d12d | 2013-03-01 20:56:36 -0800 | [diff] [blame^] | 45 | #define TAPAN_VERSION_1_0 0 |
| 46 | #define TAPAN_IS_1_0(ver) \ |
| 47 | ((ver == TAPAN_VERSION_1_0) ? 1 : 0) |
| 48 | |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 49 | enum wcd9xxx_slim_slave_addr_type { |
| 50 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TABLA, |
| 51 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TAIKO, |
| 52 | }; |
Kiran Kandi | 7b7d2ff | 2012-09-14 14:52:14 -0700 | [diff] [blame] | 53 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 54 | enum { |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 55 | /* INTR_REG 0 */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 56 | WCD9XXX_IRQ_SLIMBUS = 0, |
| 57 | WCD9XXX_IRQ_MBHC_REMOVAL, |
| 58 | WCD9XXX_IRQ_MBHC_SHORT_TERM, |
| 59 | WCD9XXX_IRQ_MBHC_PRESS, |
| 60 | WCD9XXX_IRQ_MBHC_RELEASE, |
| 61 | WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 62 | WCD9XXX_IRQ_MBHC_INSERTION, |
| 63 | WCD9XXX_IRQ_BG_PRECHARGE, |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 64 | /* INTR_REG 1 */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 65 | WCD9XXX_IRQ_PA1_STARTUP, |
| 66 | WCD9XXX_IRQ_PA2_STARTUP, |
| 67 | WCD9XXX_IRQ_PA3_STARTUP, |
| 68 | WCD9XXX_IRQ_PA4_STARTUP, |
| 69 | WCD9XXX_IRQ_PA5_STARTUP, |
| 70 | WCD9XXX_IRQ_MICBIAS1_PRECHARGE, |
| 71 | WCD9XXX_IRQ_MICBIAS2_PRECHARGE, |
| 72 | WCD9XXX_IRQ_MICBIAS3_PRECHARGE, |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 73 | /* INTR_REG 2 */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 74 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, |
| 75 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT, |
| 76 | WCD9XXX_IRQ_EAR_PA_OCPL_FAULT, |
| 77 | WCD9XXX_IRQ_HPH_L_PA_STARTUP, |
| 78 | WCD9XXX_IRQ_HPH_R_PA_STARTUP, |
| 79 | WCD9XXX_IRQ_EAR_PA_STARTUP, |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 80 | WCD9XXX_IRQ_RESERVED_0, |
| 81 | WCD9XXX_IRQ_RESERVED_1, |
| 82 | /* INTR_REG 3 */ |
| 83 | WCD9XXX_IRQ_MAD_AUDIO, |
| 84 | WCD9XXX_IRQ_MAD_BEACON, |
| 85 | WCD9XXX_IRQ_MAD_ULTRASOUND, |
| 86 | WCD9XXX_IRQ_SPEAKER_CLIPPING, |
| 87 | WCD9XXX_IRQ_MBHC_JACK_SWITCH, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 88 | WCD9XXX_NUM_IRQS, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | enum { |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 92 | TABLA_NUM_IRQS = WCD9XXX_NUM_IRQS, |
| 93 | SITAR_NUM_IRQS = WCD9XXX_NUM_IRQS, |
| 94 | TAIKO_NUM_IRQS = WCD9XXX_NUM_IRQS, |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 95 | TAPAN_NUM_IRQS = WCD9XXX_NUM_IRQS, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 99 | #define MAX(X, Y) (((int)X) >= ((int)Y) ? (X) : (Y)) |
| 100 | #define WCD9XXX_MAX_NUM_IRQS (MAX(MAX(TABLA_NUM_IRQS, SITAR_NUM_IRQS), \ |
| 101 | TAIKO_NUM_IRQS)) |
Kiran Kandi | c3b2440 | 2012-06-11 00:05:59 -0700 | [diff] [blame] | 102 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 103 | enum wcd9xxx_pm_state { |
| 104 | WCD9XXX_PM_SLEEPABLE, |
| 105 | WCD9XXX_PM_AWAKE, |
| 106 | WCD9XXX_PM_ASLEEP, |
| 107 | }; |
| 108 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 109 | /* |
| 110 | * data structure for Slimbus and I2S channel. |
| 111 | * Some of fields are only used in smilbus mode |
| 112 | */ |
| 113 | struct wcd9xxx_ch { |
| 114 | u32 sph; /* share channel handle - slimbus only */ |
| 115 | u32 ch_num; /* |
| 116 | * vitrual channel number, such as 128 -144. |
| 117 | * apply for slimbus only |
| 118 | */ |
| 119 | u16 ch_h; /* chanel handle - slimbus only */ |
| 120 | u16 port; /* |
| 121 | * tabla port for RX and TX |
| 122 | * such as 0-9 for TX and 10 -16 for RX |
| 123 | * apply for both i2s and slimbus |
| 124 | */ |
| 125 | u16 shift; /* |
| 126 | * shift bit for RX and TX |
| 127 | * apply for both i2s and slimbus |
| 128 | */ |
| 129 | struct list_head list; /* |
| 130 | * channel link list |
| 131 | * apply for both i2s and slimbus |
| 132 | */ |
| 133 | }; |
| 134 | |
| 135 | struct wcd9xxx_codec_dai_data { |
| 136 | u32 rate; /* sample rate */ |
| 137 | u32 bit_width; /* sit width 16,24,32 */ |
| 138 | struct list_head wcd9xxx_ch_list; /* channel list */ |
| 139 | u16 grph; /* slimbus group handle */ |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 140 | unsigned long ch_mask; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 141 | wait_queue_head_t dai_wait; |
| 142 | }; |
| 143 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 144 | enum wcd9xxx_intf_status { |
| 145 | WCD9XXX_INTERFACE_TYPE_PROBING, |
| 146 | WCD9XXX_INTERFACE_TYPE_SLIMBUS, |
| 147 | WCD9XXX_INTERFACE_TYPE_I2C, |
| 148 | }; |
| 149 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 150 | #define WCD9XXX_CH(xport, xshift) \ |
| 151 | {.port = xport, .shift = xshift} |
| 152 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 153 | struct wcd9xxx { |
| 154 | struct device *dev; |
| 155 | struct slim_device *slim; |
| 156 | struct slim_device *slim_slave; |
| 157 | struct mutex io_lock; |
| 158 | struct mutex xfer_lock; |
| 159 | struct mutex irq_lock; |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 160 | struct mutex nested_irq_lock; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 161 | u8 version; |
| 162 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 163 | int reset_gpio; |
| 164 | |
| 165 | int (*read_dev)(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 166 | int bytes, void *dest, bool interface_reg); |
| 167 | int (*write_dev)(struct wcd9xxx *wcd9xxx, unsigned short reg, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 168 | int bytes, void *src, bool interface_reg); |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 169 | int (*post_reset)(struct wcd9xxx *wcd9xxx); |
| 170 | |
| 171 | void *ssr_priv; |
| 172 | bool slim_device_bootup; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 173 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 174 | u32 num_of_supplies; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 175 | struct regulator_bulk_data *supplies; |
| 176 | |
| 177 | enum wcd9xxx_pm_state pm_state; |
| 178 | struct mutex pm_lock; |
| 179 | /* pm_wq notifies change of pm_state */ |
| 180 | wait_queue_head_t pm_wq; |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 181 | struct pm_qos_request pm_qos_req; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 182 | int wlock_holders; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 183 | |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 184 | u8 idbyte[4]; |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 185 | |
| 186 | unsigned int irq_base; |
| 187 | unsigned int irq; |
| 188 | u8 irq_masks_cur[WCD9XXX_NUM_IRQ_REGS]; |
| 189 | u8 irq_masks_cache[WCD9XXX_NUM_IRQ_REGS]; |
| 190 | bool irq_level_high[WCD9XXX_MAX_NUM_IRQS]; |
| 191 | int num_irqs; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 192 | /* Slimbus or I2S port */ |
| 193 | u32 num_rx_port; |
| 194 | u32 num_tx_port; |
| 195 | struct wcd9xxx_ch *rx_chs; |
| 196 | struct wcd9xxx_ch *tx_chs; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 197 | u32 mclk_rate; |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 198 | |
| 199 | enum wcd9xxx_slim_slave_addr_type slim_slave_type; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | int wcd9xxx_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg); |
| 203 | int wcd9xxx_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 204 | u8 val); |
| 205 | int wcd9xxx_interface_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg); |
| 206 | int wcd9xxx_interface_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 207 | u8 val); |
| 208 | int wcd9xxx_bulk_read(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 209 | int count, u8 *buf); |
| 210 | int wcd9xxx_bulk_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 211 | int count, u8 *buf); |
| 212 | int wcd9xxx_irq_init(struct wcd9xxx *wcd9xxx); |
| 213 | void wcd9xxx_irq_exit(struct wcd9xxx *wcd9xxx); |
| 214 | int wcd9xxx_get_logical_addresses(u8 *pgd_la, u8 *inf_la); |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 215 | enum wcd9xxx_intf_status wcd9xxx_get_intf_type(void); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 216 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 217 | bool wcd9xxx_lock_sleep(struct wcd9xxx *wcd9xxx); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 218 | void wcd9xxx_unlock_sleep(struct wcd9xxx *wcd9xxx); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 219 | void wcd9xxx_nested_irq_lock(struct wcd9xxx *wcd9xxx); |
| 220 | void wcd9xxx_nested_irq_unlock(struct wcd9xxx *wcd9xxx); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 221 | enum wcd9xxx_pm_state wcd9xxx_pm_cmpxchg(struct wcd9xxx *wcd9xxx, |
| 222 | enum wcd9xxx_pm_state o, |
| 223 | enum wcd9xxx_pm_state n); |
| 224 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 225 | int wcd9xxx_request_irq(struct wcd9xxx *wcd9xxx, int irq, |
| 226 | irq_handler_t handler, const char *name, void *data); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 227 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 228 | void wcd9xxx_free_irq(struct wcd9xxx *wcd9xxx, int irq, void *data); |
| 229 | void wcd9xxx_enable_irq(struct wcd9xxx *wcd9xxx, int irq); |
| 230 | void wcd9xxx_disable_irq(struct wcd9xxx *wcd9xxx, int irq); |
| 231 | void wcd9xxx_disable_irq_sync(struct wcd9xxx *wcd9xxx, int irq); |
Rohit Vaswani | 750bee1 | 2012-09-20 16:18:10 -0700 | [diff] [blame] | 232 | #if defined(CONFIG_WCD9310_CODEC) || \ |
| 233 | defined(CONFIG_WCD9304_CODEC) || \ |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 234 | defined(CONFIG_WCD9320_CODEC) || \ |
| 235 | defined(CONFIG_WCD9306_CODEC) |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 236 | int __init wcd9xxx_irq_of_init(struct device_node *node, |
| 237 | struct device_node *parent); |
Rohit Vaswani | 750bee1 | 2012-09-20 16:18:10 -0700 | [diff] [blame] | 238 | #else |
| 239 | static inline int __init wcd9xxx_irq_of_init(struct device_node *node, |
| 240 | struct device_node *parent) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 244 | #endif /* CONFIG_OF */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 245 | #endif |