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