Michael Bohan | 26324a2 | 2013-03-20 10:15:33 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [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 | |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 13 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 14 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/spmi.h> |
| 18 | #include <linux/platform_device.h> |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 19 | #include <linux/debugfs.h> |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 20 | #include <linux/gpio.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/of_gpio.h> |
| 24 | #include <linux/of_irq.h> |
Michael Bohan | 0b24fb1 | 2012-06-01 10:30:12 -0700 | [diff] [blame] | 25 | #include <linux/export.h> |
| 26 | #include <linux/module.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 27 | #include <linux/export.h> |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 28 | #include <linux/qpnp/pin.h> |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 29 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 30 | #define Q_REG_ADDR(q_spec, reg_index) \ |
| 31 | ((q_spec)->offset + reg_index) |
| 32 | |
| 33 | #define Q_REG_STATUS1 0x8 |
Michael Bohan | ffa1681 | 2012-08-15 18:11:49 -0700 | [diff] [blame] | 34 | #define Q_REG_STATUS1_VAL_MASK 0x1 |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 35 | #define Q_REG_STATUS1_GPIO_EN_REV0_MASK 0x2 |
| 36 | #define Q_REG_STATUS1_GPIO_EN_MASK 0x80 |
Michael Bohan | ffa1681 | 2012-08-15 18:11:49 -0700 | [diff] [blame] | 37 | #define Q_REG_STATUS1_MPP_EN_MASK 0x80 |
| 38 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 39 | #define Q_NUM_CTL_REGS 0xD |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 40 | |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 41 | /* revision registers base address offsets */ |
| 42 | #define Q_REG_DIG_MINOR_REV 0x0 |
| 43 | #define Q_REG_DIG_MAJOR_REV 0x1 |
| 44 | #define Q_REG_ANA_MINOR_REV 0x2 |
| 45 | |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 46 | /* type registers base address offsets */ |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 47 | #define Q_REG_TYPE 0x4 |
| 48 | #define Q_REG_SUBTYPE 0x5 |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 49 | |
| 50 | /* gpio peripheral type and subtype values */ |
| 51 | #define Q_GPIO_TYPE 0x10 |
Michael Bohan | e824a6e | 2012-08-14 14:35:37 -0700 | [diff] [blame] | 52 | #define Q_GPIO_SUBTYPE_GPIO_4CH 0x1 |
| 53 | #define Q_GPIO_SUBTYPE_GPIOC_4CH 0x5 |
| 54 | #define Q_GPIO_SUBTYPE_GPIO_8CH 0x9 |
| 55 | #define Q_GPIO_SUBTYPE_GPIOC_8CH 0xD |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 56 | |
| 57 | /* mpp peripheral type and subtype values */ |
| 58 | #define Q_MPP_TYPE 0x11 |
Michael Bohan | ab7aafa | 2012-08-11 12:34:46 -0700 | [diff] [blame] | 59 | #define Q_MPP_SUBTYPE_4CH_NO_ANA_OUT 0x3 |
| 60 | #define Q_MPP_SUBTYPE_4CH_NO_SINK 0x5 |
Michael Bohan | e824a6e | 2012-08-14 14:35:37 -0700 | [diff] [blame] | 61 | #define Q_MPP_SUBTYPE_4CH_FULL_FUNC 0x7 |
| 62 | #define Q_MPP_SUBTYPE_8CH_FULL_FUNC 0xF |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 63 | |
| 64 | /* control register base address offsets */ |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 65 | #define Q_REG_MODE_CTL 0x40 |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 66 | #define Q_REG_DIG_VIN_CTL 0x41 |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 67 | #define Q_REG_DIG_PULL_CTL 0x42 |
| 68 | #define Q_REG_DIG_IN_CTL 0x43 |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 69 | #define Q_REG_DIG_OUT_CTL 0x45 |
| 70 | #define Q_REG_EN_CTL 0x46 |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 71 | #define Q_REG_AOUT_CTL 0x48 |
| 72 | #define Q_REG_AIN_CTL 0x4A |
| 73 | #define Q_REG_SINK_CTL 0x4C |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 74 | |
| 75 | /* control register regs array indices */ |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 76 | #define Q_REG_I_MODE_CTL 0 |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 77 | #define Q_REG_I_DIG_VIN_CTL 1 |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 78 | #define Q_REG_I_DIG_PULL_CTL 2 |
| 79 | #define Q_REG_I_DIG_IN_CTL 3 |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 80 | #define Q_REG_I_DIG_OUT_CTL 5 |
| 81 | #define Q_REG_I_EN_CTL 6 |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 82 | #define Q_REG_I_AOUT_CTL 8 |
| 83 | #define Q_REG_I_AIN_CTL 10 |
| 84 | #define Q_REG_I_SINK_CTL 12 |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 85 | |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 86 | /* control reg: mode */ |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 87 | #define Q_REG_OUT_INVERT_SHIFT 0 |
| 88 | #define Q_REG_OUT_INVERT_MASK 0x1 |
| 89 | #define Q_REG_SRC_SEL_SHIFT 1 |
| 90 | #define Q_REG_SRC_SEL_MASK 0xE |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 91 | #define Q_REG_MODE_SEL_SHIFT 4 |
| 92 | #define Q_REG_MODE_SEL_MASK 0x70 |
| 93 | |
| 94 | /* control reg: dig_vin */ |
| 95 | #define Q_REG_VIN_SHIFT 0 |
| 96 | #define Q_REG_VIN_MASK 0x7 |
| 97 | |
| 98 | /* control reg: dig_pull */ |
| 99 | #define Q_REG_PULL_SHIFT 0 |
| 100 | #define Q_REG_PULL_MASK 0x7 |
| 101 | |
| 102 | /* control reg: dig_out */ |
| 103 | #define Q_REG_OUT_STRENGTH_SHIFT 0 |
| 104 | #define Q_REG_OUT_STRENGTH_MASK 0x3 |
| 105 | #define Q_REG_OUT_TYPE_SHIFT 4 |
| 106 | #define Q_REG_OUT_TYPE_MASK 0x30 |
| 107 | |
| 108 | /* control reg: en */ |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 109 | #define Q_REG_MASTER_EN_SHIFT 7 |
| 110 | #define Q_REG_MASTER_EN_MASK 0x80 |
| 111 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 112 | /* control reg: ana_out */ |
| 113 | #define Q_REG_AOUT_REF_SHIFT 0 |
| 114 | #define Q_REG_AOUT_REF_MASK 0x7 |
| 115 | |
| 116 | /* control reg: ana_in */ |
| 117 | #define Q_REG_AIN_ROUTE_SHIFT 0 |
| 118 | #define Q_REG_AIN_ROUTE_MASK 0x7 |
| 119 | |
| 120 | /* control reg: sink */ |
| 121 | #define Q_REG_CS_OUT_SHIFT 0 |
| 122 | #define Q_REG_CS_OUT_MASK 0x7 |
| 123 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 124 | enum qpnp_pin_param_type { |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 125 | Q_PIN_CFG_MODE, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 126 | Q_PIN_CFG_OUTPUT_TYPE, |
| 127 | Q_PIN_CFG_INVERT, |
| 128 | Q_PIN_CFG_PULL, |
| 129 | Q_PIN_CFG_VIN_SEL, |
| 130 | Q_PIN_CFG_OUT_STRENGTH, |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 131 | Q_PIN_CFG_SRC_SEL, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 132 | Q_PIN_CFG_MASTER_EN, |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 133 | Q_PIN_CFG_AOUT_REF, |
| 134 | Q_PIN_CFG_AIN_ROUTE, |
| 135 | Q_PIN_CFG_CS_OUT, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 136 | Q_PIN_CFG_INVALID, |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 139 | #define Q_NUM_PARAMS Q_PIN_CFG_INVALID |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 140 | |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 141 | /* param error checking */ |
Michael Bohan | 1c3d94f | 2012-08-11 14:33:03 -0700 | [diff] [blame] | 142 | #define QPNP_PIN_GPIO_MODE_INVALID 3 |
| 143 | #define QPNP_PIN_MPP_MODE_INVALID 7 |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 144 | #define QPNP_PIN_INVERT_INVALID 2 |
| 145 | #define QPNP_PIN_OUT_BUF_INVALID 3 |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 146 | #define QPNP_PIN_VIN_4CH_INVALID 5 |
| 147 | #define QPNP_PIN_VIN_8CH_INVALID 8 |
| 148 | #define QPNP_PIN_GPIO_PULL_INVALID 6 |
| 149 | #define QPNP_PIN_MPP_PULL_INVALID 4 |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 150 | #define QPNP_PIN_OUT_STRENGTH_INVALID 4 |
| 151 | #define QPNP_PIN_SRC_INVALID 8 |
| 152 | #define QPNP_PIN_MASTER_INVALID 2 |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 153 | #define QPNP_PIN_AOUT_REF_INVALID 8 |
| 154 | #define QPNP_PIN_AIN_ROUTE_INVALID 8 |
| 155 | #define QPNP_PIN_CS_OUT_INVALID 8 |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 156 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 157 | struct qpnp_pin_spec { |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 158 | uint8_t slave; /* 0-15 */ |
| 159 | uint16_t offset; /* 0-255 */ |
| 160 | uint32_t gpio_chip_idx; /* offset from gpio_chip base */ |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 161 | uint32_t pmic_pin; /* PMIC pin number */ |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 162 | int irq; /* logical IRQ number */ |
| 163 | u8 regs[Q_NUM_CTL_REGS]; /* Control regs */ |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 164 | u8 num_ctl_regs; /* usable number on this pin */ |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 165 | u8 type; /* peripheral type */ |
| 166 | u8 subtype; /* peripheral subtype */ |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 167 | u8 dig_major_rev; |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 168 | struct device_node *node; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 169 | enum qpnp_pin_param_type params[Q_NUM_PARAMS]; |
| 170 | struct qpnp_pin_chip *q_chip; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 171 | }; |
| 172 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 173 | struct qpnp_pin_chip { |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 174 | struct gpio_chip gpio_chip; |
| 175 | struct spmi_device *spmi; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 176 | struct qpnp_pin_spec **pmic_pins; |
| 177 | struct qpnp_pin_spec **chip_gpios; |
| 178 | uint32_t pmic_pin_lowest; |
| 179 | uint32_t pmic_pin_highest; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 180 | struct device_node *int_ctrl; |
| 181 | struct list_head chip_list; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 182 | struct dentry *dfs_dir; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 183 | }; |
| 184 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 185 | static LIST_HEAD(qpnp_pin_chips); |
| 186 | static DEFINE_MUTEX(qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 187 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 188 | static inline void qpnp_pmic_pin_set_spec(struct qpnp_pin_chip *q_chip, |
| 189 | uint32_t pmic_pin, |
| 190 | struct qpnp_pin_spec *spec) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 191 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 192 | q_chip->pmic_pins[pmic_pin - q_chip->pmic_pin_lowest] = spec; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 195 | static inline struct qpnp_pin_spec *qpnp_pmic_pin_get_spec( |
| 196 | struct qpnp_pin_chip *q_chip, |
| 197 | uint32_t pmic_pin) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 198 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 199 | if (pmic_pin < q_chip->pmic_pin_lowest || |
| 200 | pmic_pin > q_chip->pmic_pin_highest) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 201 | return NULL; |
| 202 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 203 | return q_chip->pmic_pins[pmic_pin - q_chip->pmic_pin_lowest]; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 206 | static inline struct qpnp_pin_spec *qpnp_chip_gpio_get_spec( |
| 207 | struct qpnp_pin_chip *q_chip, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 208 | uint32_t chip_gpio) |
| 209 | { |
| 210 | if (chip_gpio > q_chip->gpio_chip.ngpio) |
| 211 | return NULL; |
| 212 | |
| 213 | return q_chip->chip_gpios[chip_gpio]; |
| 214 | } |
| 215 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 216 | static inline void qpnp_chip_gpio_set_spec(struct qpnp_pin_chip *q_chip, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 217 | uint32_t chip_gpio, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 218 | struct qpnp_pin_spec *spec) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 219 | { |
| 220 | q_chip->chip_gpios[chip_gpio] = spec; |
| 221 | } |
| 222 | |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 223 | /* |
| 224 | * Determines whether a specified param's configuration is correct. |
| 225 | * This check is two tier. First a check is done whether the hardware |
| 226 | * supports this param and value requested. The second check validates |
| 227 | * that the configuration is correct, given the fact that the hardware |
| 228 | * supports it. |
| 229 | * |
| 230 | * Returns |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 231 | * -ENXIO is the hardware does not support this param. |
| 232 | * -EINVAL if the the hardware does support this param, but the |
| 233 | * requested value is outside the supported range. |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 234 | */ |
| 235 | static int qpnp_pin_check_config(enum qpnp_pin_param_type idx, |
| 236 | struct qpnp_pin_spec *q_spec, uint32_t val) |
| 237 | { |
| 238 | switch (idx) { |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 239 | case Q_PIN_CFG_MODE: |
Michael Bohan | 1c3d94f | 2012-08-11 14:33:03 -0700 | [diff] [blame] | 240 | if (q_spec->type == Q_GPIO_TYPE && |
| 241 | val >= QPNP_PIN_GPIO_MODE_INVALID) |
| 242 | return -EINVAL; |
| 243 | else if (q_spec->type == Q_MPP_TYPE && |
| 244 | val >= QPNP_PIN_MPP_MODE_INVALID) |
| 245 | return -EINVAL; |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 246 | break; |
| 247 | case Q_PIN_CFG_OUTPUT_TYPE: |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 248 | if (q_spec->type != Q_GPIO_TYPE) |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 249 | return -ENXIO; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 250 | if ((val == QPNP_PIN_OUT_BUF_OPEN_DRAIN_NMOS || |
| 251 | val == QPNP_PIN_OUT_BUF_OPEN_DRAIN_PMOS) && |
| 252 | (q_spec->subtype == Q_GPIO_SUBTYPE_GPIOC_4CH || |
| 253 | (q_spec->subtype == Q_GPIO_SUBTYPE_GPIOC_8CH))) |
| 254 | return -EINVAL; |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 255 | else if (val >= QPNP_PIN_OUT_BUF_INVALID) |
| 256 | return -EINVAL; |
| 257 | break; |
| 258 | case Q_PIN_CFG_INVERT: |
| 259 | if (val >= QPNP_PIN_INVERT_INVALID) |
| 260 | return -EINVAL; |
| 261 | break; |
| 262 | case Q_PIN_CFG_PULL: |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 263 | if (q_spec->type == Q_GPIO_TYPE && |
| 264 | val >= QPNP_PIN_GPIO_PULL_INVALID) |
| 265 | return -EINVAL; |
| 266 | if (q_spec->type == Q_MPP_TYPE && |
| 267 | val >= QPNP_PIN_MPP_PULL_INVALID) |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 268 | return -EINVAL; |
| 269 | break; |
| 270 | case Q_PIN_CFG_VIN_SEL: |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 271 | if (val >= QPNP_PIN_VIN_8CH_INVALID) |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 272 | return -EINVAL; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 273 | else if (val >= QPNP_PIN_VIN_4CH_INVALID) { |
| 274 | if (q_spec->type == Q_GPIO_TYPE && |
| 275 | (q_spec->subtype == Q_GPIO_SUBTYPE_GPIO_4CH || |
| 276 | q_spec->subtype == Q_GPIO_SUBTYPE_GPIOC_4CH)) |
| 277 | return -EINVAL; |
| 278 | if (q_spec->type == Q_MPP_TYPE && |
| 279 | (q_spec->subtype == Q_MPP_SUBTYPE_4CH_NO_ANA_OUT || |
| 280 | q_spec->subtype == Q_MPP_SUBTYPE_4CH_NO_SINK || |
| 281 | q_spec->subtype == Q_MPP_SUBTYPE_4CH_FULL_FUNC)) |
| 282 | return -EINVAL; |
| 283 | } |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 284 | break; |
| 285 | case Q_PIN_CFG_OUT_STRENGTH: |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 286 | if (q_spec->type != Q_GPIO_TYPE) |
| 287 | return -ENXIO; |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 288 | if (val >= QPNP_PIN_OUT_STRENGTH_INVALID || |
| 289 | val == 0) |
| 290 | return -EINVAL; |
| 291 | break; |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 292 | case Q_PIN_CFG_SRC_SEL: |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 293 | if (q_spec->type == Q_MPP_TYPE && |
| 294 | (val == QPNP_PIN_SEL_FUNC_1 || |
| 295 | val == QPNP_PIN_SEL_FUNC_2)) |
| 296 | return -EINVAL; |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 297 | if (val >= QPNP_PIN_SRC_INVALID) |
| 298 | return -EINVAL; |
| 299 | break; |
| 300 | case Q_PIN_CFG_MASTER_EN: |
| 301 | if (val >= QPNP_PIN_MASTER_INVALID) |
| 302 | return -EINVAL; |
| 303 | break; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 304 | case Q_PIN_CFG_AOUT_REF: |
| 305 | if (q_spec->type != Q_MPP_TYPE) |
| 306 | return -ENXIO; |
| 307 | if (q_spec->subtype == Q_MPP_SUBTYPE_4CH_NO_ANA_OUT) |
| 308 | return -ENXIO; |
| 309 | if (val >= QPNP_PIN_AOUT_REF_INVALID) |
| 310 | return -EINVAL; |
| 311 | break; |
| 312 | case Q_PIN_CFG_AIN_ROUTE: |
| 313 | if (q_spec->type != Q_MPP_TYPE) |
| 314 | return -ENXIO; |
| 315 | if (val >= QPNP_PIN_AIN_ROUTE_INVALID) |
| 316 | return -EINVAL; |
| 317 | break; |
| 318 | case Q_PIN_CFG_CS_OUT: |
| 319 | if (q_spec->type != Q_MPP_TYPE) |
| 320 | return -ENXIO; |
| 321 | if (q_spec->subtype == Q_MPP_SUBTYPE_4CH_NO_SINK) |
| 322 | return -ENXIO; |
| 323 | if (val >= QPNP_PIN_CS_OUT_INVALID) |
| 324 | return -EINVAL; |
| 325 | break; |
| 326 | |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 327 | default: |
| 328 | pr_err("invalid param type %u specified\n", idx); |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | #define Q_CHK_INVALID(idx, q_spec, val) \ |
| 335 | (qpnp_pin_check_config(idx, q_spec, val) == -EINVAL) |
| 336 | |
| 337 | static int qpnp_pin_check_constraints(struct qpnp_pin_spec *q_spec, |
| 338 | struct qpnp_pin_cfg *param) |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 339 | { |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 340 | int pin = q_spec->pmic_pin; |
| 341 | const char *name; |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 342 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 343 | name = (q_spec->type == Q_GPIO_TYPE) ? "gpio" : "mpp"; |
| 344 | |
| 345 | if (Q_CHK_INVALID(Q_PIN_CFG_MODE, q_spec, param->mode)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 346 | pr_err("invalid direction value %d for %s %d\n", |
| 347 | param->mode, name, pin); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 348 | else if (Q_CHK_INVALID(Q_PIN_CFG_INVERT, q_spec, param->invert)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 349 | pr_err("invalid invert polarity value %d for %s %d\n", |
| 350 | param->invert, name, pin); |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 351 | else if (Q_CHK_INVALID(Q_PIN_CFG_SRC_SEL, q_spec, param->src_sel)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 352 | pr_err("invalid source select value %d for %s %d\n", |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 353 | param->src_sel, name, pin); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 354 | else if (Q_CHK_INVALID(Q_PIN_CFG_OUT_STRENGTH, |
| 355 | q_spec, param->out_strength)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 356 | pr_err("invalid out strength value %d for %s %d\n", |
| 357 | param->out_strength, name, pin); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 358 | else if (Q_CHK_INVALID(Q_PIN_CFG_OUTPUT_TYPE, |
| 359 | q_spec, param->output_type)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 360 | pr_err("invalid out type value %d for %s %d\n", |
| 361 | param->output_type, name, pin); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 362 | else if (Q_CHK_INVALID(Q_PIN_CFG_VIN_SEL, q_spec, param->vin_sel)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 363 | pr_err("invalid vin select %d value for %s %d\n", |
| 364 | param->vin_sel, name, pin); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 365 | else if (Q_CHK_INVALID(Q_PIN_CFG_PULL, q_spec, param->pull)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 366 | pr_err("invalid pull value %d for pin %s %d\n", |
| 367 | param->pull, name, pin); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 368 | else if (Q_CHK_INVALID(Q_PIN_CFG_MASTER_EN, q_spec, param->master_en)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 369 | pr_err("invalid master_en value %d for %s %d\n", |
| 370 | param->master_en, name, pin); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 371 | else if (Q_CHK_INVALID(Q_PIN_CFG_AOUT_REF, q_spec, param->aout_ref)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 372 | pr_err("invalid aout_reg value %d for %s %d\n", |
| 373 | param->aout_ref, name, pin); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 374 | else if (Q_CHK_INVALID(Q_PIN_CFG_AIN_ROUTE, q_spec, param->ain_route)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 375 | pr_err("invalid ain_route value %d for %s %d\n", |
| 376 | param->ain_route, name, pin); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 377 | else if (Q_CHK_INVALID(Q_PIN_CFG_CS_OUT, q_spec, param->cs_out)) |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 378 | pr_err("invalid cs_out value %d for %s %d\n", |
| 379 | param->cs_out, name, pin); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 380 | else |
| 381 | return 0; |
| 382 | |
| 383 | return -EINVAL; |
| 384 | } |
| 385 | |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 386 | static inline u8 q_reg_get(u8 *reg, int shift, int mask) |
| 387 | { |
| 388 | return (*reg & mask) >> shift; |
| 389 | } |
| 390 | |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 391 | static inline void q_reg_set(u8 *reg, int shift, int mask, int value) |
| 392 | { |
| 393 | *reg |= (value << shift) & mask; |
| 394 | } |
| 395 | |
| 396 | static inline void q_reg_clr_set(u8 *reg, int shift, int mask, int value) |
| 397 | { |
| 398 | *reg &= ~mask; |
| 399 | *reg |= (value << shift) & mask; |
| 400 | } |
| 401 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 402 | /* |
| 403 | * Calculate the minimum number of registers that must be read / written |
| 404 | * in order to satisfy the full feature set of the given pin. |
| 405 | */ |
| 406 | static int qpnp_pin_ctl_regs_init(struct qpnp_pin_spec *q_spec) |
| 407 | { |
| 408 | if (q_spec->type == Q_GPIO_TYPE) |
| 409 | q_spec->num_ctl_regs = 7; |
| 410 | else if (q_spec->type == Q_MPP_TYPE) |
| 411 | switch (q_spec->subtype) { |
| 412 | case Q_MPP_SUBTYPE_4CH_NO_SINK: |
| 413 | q_spec->num_ctl_regs = 12; |
| 414 | break; |
| 415 | case Q_MPP_SUBTYPE_4CH_NO_ANA_OUT: |
| 416 | case Q_MPP_SUBTYPE_4CH_FULL_FUNC: |
| 417 | case Q_MPP_SUBTYPE_8CH_FULL_FUNC: |
| 418 | q_spec->num_ctl_regs = 13; |
| 419 | break; |
| 420 | default: |
| 421 | pr_err("Invalid MPP subtype 0x%x\n", q_spec->subtype); |
| 422 | return -EINVAL; |
| 423 | } |
| 424 | else { |
| 425 | pr_err("Invalid type 0x%x\n", q_spec->type); |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static int qpnp_pin_read_regs(struct qpnp_pin_chip *q_chip, |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 432 | struct qpnp_pin_spec *q_spec) |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 433 | { |
| 434 | int bytes_left = q_spec->num_ctl_regs; |
| 435 | int rc; |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 436 | char *buf_p = &q_spec->regs[0]; |
| 437 | u16 reg_addr = Q_REG_ADDR(q_spec, Q_REG_MODE_CTL); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 438 | |
| 439 | while (bytes_left > 0) { |
| 440 | rc = spmi_ext_register_readl(q_chip->spmi->ctrl, q_spec->slave, |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 441 | reg_addr, buf_p, bytes_left < 8 ? bytes_left : 8); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 442 | if (rc) |
| 443 | return rc; |
| 444 | bytes_left -= 8; |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 445 | buf_p += 8; |
| 446 | reg_addr += 8; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 447 | } |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int qpnp_pin_write_regs(struct qpnp_pin_chip *q_chip, |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 452 | struct qpnp_pin_spec *q_spec) |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 453 | { |
| 454 | int bytes_left = q_spec->num_ctl_regs; |
| 455 | int rc; |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 456 | char *buf_p = &q_spec->regs[0]; |
| 457 | u16 reg_addr = Q_REG_ADDR(q_spec, Q_REG_MODE_CTL); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 458 | |
| 459 | while (bytes_left > 0) { |
| 460 | rc = spmi_ext_register_writel(q_chip->spmi->ctrl, q_spec->slave, |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 461 | reg_addr, buf_p, bytes_left < 8 ? bytes_left : 8); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 462 | if (rc) |
| 463 | return rc; |
| 464 | bytes_left -= 8; |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 465 | buf_p += 8; |
| 466 | reg_addr += 8; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 471 | static int qpnp_pin_cache_regs(struct qpnp_pin_chip *q_chip, |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 472 | struct qpnp_pin_spec *q_spec) |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 473 | { |
| 474 | int rc; |
| 475 | struct device *dev = &q_chip->spmi->dev; |
| 476 | |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 477 | rc = qpnp_pin_read_regs(q_chip, q_spec); |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 478 | if (rc) |
| 479 | dev_err(dev, "%s: unable to read control regs\n", __func__); |
| 480 | |
| 481 | return rc; |
| 482 | } |
| 483 | |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 484 | #define Q_HAVE_HW_SP(idx, q_spec, val) \ |
| 485 | (qpnp_pin_check_config(idx, q_spec, val) == 0) |
| 486 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 487 | static int _qpnp_pin_config(struct qpnp_pin_chip *q_chip, |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 488 | struct qpnp_pin_spec *q_spec, |
| 489 | struct qpnp_pin_cfg *param) |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 490 | { |
| 491 | struct device *dev = &q_chip->spmi->dev; |
| 492 | int rc; |
| 493 | |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 494 | rc = qpnp_pin_check_constraints(q_spec, param); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 495 | if (rc) |
| 496 | goto gpio_cfg; |
| 497 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 498 | /* set mode */ |
| 499 | if (Q_HAVE_HW_SP(Q_PIN_CFG_MODE, q_spec, param->mode)) |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 500 | q_reg_clr_set(&q_spec->regs[Q_REG_I_MODE_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 501 | Q_REG_MODE_SEL_SHIFT, Q_REG_MODE_SEL_MASK, |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 502 | param->mode); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 503 | |
| 504 | /* output specific configuration */ |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 505 | if (Q_HAVE_HW_SP(Q_PIN_CFG_INVERT, q_spec, param->invert)) |
| 506 | q_reg_clr_set(&q_spec->regs[Q_REG_I_MODE_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 507 | Q_REG_OUT_INVERT_SHIFT, Q_REG_OUT_INVERT_MASK, |
| 508 | param->invert); |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 509 | if (Q_HAVE_HW_SP(Q_PIN_CFG_SRC_SEL, q_spec, param->src_sel)) |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 510 | q_reg_clr_set(&q_spec->regs[Q_REG_I_MODE_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 511 | Q_REG_SRC_SEL_SHIFT, Q_REG_SRC_SEL_MASK, |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 512 | param->src_sel); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 513 | if (Q_HAVE_HW_SP(Q_PIN_CFG_OUT_STRENGTH, q_spec, param->out_strength)) |
| 514 | q_reg_clr_set(&q_spec->regs[Q_REG_I_DIG_OUT_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 515 | Q_REG_OUT_STRENGTH_SHIFT, Q_REG_OUT_STRENGTH_MASK, |
| 516 | param->out_strength); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 517 | if (Q_HAVE_HW_SP(Q_PIN_CFG_OUTPUT_TYPE, q_spec, param->output_type)) |
| 518 | q_reg_clr_set(&q_spec->regs[Q_REG_I_DIG_OUT_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 519 | Q_REG_OUT_TYPE_SHIFT, Q_REG_OUT_TYPE_MASK, |
| 520 | param->output_type); |
| 521 | |
| 522 | /* config applicable for both input / output */ |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 523 | if (Q_HAVE_HW_SP(Q_PIN_CFG_VIN_SEL, q_spec, param->vin_sel)) |
| 524 | q_reg_clr_set(&q_spec->regs[Q_REG_I_DIG_VIN_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 525 | Q_REG_VIN_SHIFT, Q_REG_VIN_MASK, |
| 526 | param->vin_sel); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 527 | if (Q_HAVE_HW_SP(Q_PIN_CFG_PULL, q_spec, param->pull)) |
| 528 | q_reg_clr_set(&q_spec->regs[Q_REG_I_DIG_PULL_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 529 | Q_REG_PULL_SHIFT, Q_REG_PULL_MASK, |
| 530 | param->pull); |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 531 | if (Q_HAVE_HW_SP(Q_PIN_CFG_MASTER_EN, q_spec, param->master_en)) |
| 532 | q_reg_clr_set(&q_spec->regs[Q_REG_I_EN_CTL], |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 533 | Q_REG_MASTER_EN_SHIFT, Q_REG_MASTER_EN_MASK, |
| 534 | param->master_en); |
| 535 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 536 | /* mpp specific config */ |
| 537 | if (Q_HAVE_HW_SP(Q_PIN_CFG_AOUT_REF, q_spec, param->aout_ref)) |
| 538 | q_reg_clr_set(&q_spec->regs[Q_REG_I_AOUT_CTL], |
| 539 | Q_REG_AOUT_REF_SHIFT, Q_REG_AOUT_REF_MASK, |
| 540 | param->aout_ref); |
| 541 | if (Q_HAVE_HW_SP(Q_PIN_CFG_AIN_ROUTE, q_spec, param->ain_route)) |
| 542 | q_reg_clr_set(&q_spec->regs[Q_REG_I_AIN_CTL], |
| 543 | Q_REG_AIN_ROUTE_SHIFT, Q_REG_AIN_ROUTE_MASK, |
| 544 | param->ain_route); |
| 545 | if (Q_HAVE_HW_SP(Q_PIN_CFG_CS_OUT, q_spec, param->cs_out)) |
| 546 | q_reg_clr_set(&q_spec->regs[Q_REG_I_SINK_CTL], |
| 547 | Q_REG_CS_OUT_SHIFT, Q_REG_CS_OUT_MASK, |
| 548 | param->cs_out); |
| 549 | |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 550 | rc = qpnp_pin_write_regs(q_chip, q_spec); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 551 | if (rc) { |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 552 | dev_err(&q_chip->spmi->dev, "%s: unable to write master enable\n", |
| 553 | __func__); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 554 | goto gpio_cfg; |
| 555 | } |
| 556 | |
| 557 | return 0; |
| 558 | |
| 559 | gpio_cfg: |
Michael Bohan | 91c5a04 | 2012-08-11 13:29:42 -0700 | [diff] [blame] | 560 | dev_err(dev, "%s: unable to set default config for pmic pin %d\n", |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 561 | __func__, q_spec->pmic_pin); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 562 | |
| 563 | return rc; |
| 564 | } |
| 565 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 566 | int qpnp_pin_config(int gpio, struct qpnp_pin_cfg *param) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 567 | { |
| 568 | int rc, chip_offset; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 569 | struct qpnp_pin_chip *q_chip; |
| 570 | struct qpnp_pin_spec *q_spec = NULL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 571 | struct gpio_chip *gpio_chip; |
| 572 | |
| 573 | if (param == NULL) |
| 574 | return -EINVAL; |
| 575 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 576 | mutex_lock(&qpnp_pin_chips_lock); |
| 577 | list_for_each_entry(q_chip, &qpnp_pin_chips, chip_list) { |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 578 | gpio_chip = &q_chip->gpio_chip; |
| 579 | if (gpio >= gpio_chip->base |
| 580 | && gpio < gpio_chip->base + gpio_chip->ngpio) { |
| 581 | chip_offset = gpio - gpio_chip->base; |
| 582 | q_spec = qpnp_chip_gpio_get_spec(q_chip, chip_offset); |
| 583 | if (WARN_ON(!q_spec)) { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 584 | mutex_unlock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 585 | return -ENODEV; |
| 586 | } |
| 587 | break; |
| 588 | } |
| 589 | } |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 590 | mutex_unlock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 591 | |
Zhenhua Huang | 30acf24 | 2013-07-11 01:52:36 +0800 | [diff] [blame] | 592 | if (!q_spec) |
| 593 | return -ENODEV; |
| 594 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 595 | rc = _qpnp_pin_config(q_chip, q_spec, param); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 596 | |
| 597 | return rc; |
| 598 | } |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 599 | EXPORT_SYMBOL(qpnp_pin_config); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 600 | |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 601 | #define Q_MAX_CHIP_NAME 128 |
| 602 | int qpnp_pin_map(const char *name, uint32_t pmic_pin) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 603 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 604 | struct qpnp_pin_chip *q_chip; |
| 605 | struct qpnp_pin_spec *q_spec = NULL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 606 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 607 | mutex_lock(&qpnp_pin_chips_lock); |
| 608 | list_for_each_entry(q_chip, &qpnp_pin_chips, chip_list) { |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 609 | if (strncmp(q_chip->gpio_chip.label, name, |
| 610 | Q_MAX_CHIP_NAME) != 0) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 611 | continue; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 612 | if (q_chip->pmic_pin_lowest <= pmic_pin && |
| 613 | q_chip->pmic_pin_highest >= pmic_pin) { |
| 614 | q_spec = qpnp_pmic_pin_get_spec(q_chip, pmic_pin); |
| 615 | mutex_unlock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 616 | if (WARN_ON(!q_spec)) |
| 617 | return -ENODEV; |
| 618 | return q_chip->gpio_chip.base + q_spec->gpio_chip_idx; |
| 619 | } |
| 620 | } |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 621 | mutex_unlock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 622 | return -EINVAL; |
| 623 | } |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 624 | EXPORT_SYMBOL(qpnp_pin_map); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 625 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 626 | static int qpnp_pin_to_irq(struct gpio_chip *gpio_chip, unsigned offset) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 627 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 628 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(gpio_chip->dev); |
| 629 | struct qpnp_pin_spec *q_spec; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 630 | |
| 631 | q_spec = qpnp_chip_gpio_get_spec(q_chip, offset); |
| 632 | if (!q_spec) |
| 633 | return -EINVAL; |
| 634 | |
| 635 | return q_spec->irq; |
| 636 | } |
| 637 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 638 | static int qpnp_pin_get(struct gpio_chip *gpio_chip, unsigned offset) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 639 | { |
| 640 | int rc, ret_val; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 641 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(gpio_chip->dev); |
| 642 | struct qpnp_pin_spec *q_spec = NULL; |
Michael Bohan | ffa1681 | 2012-08-15 18:11:49 -0700 | [diff] [blame] | 643 | u8 buf[1], en_mask; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 644 | |
| 645 | if (WARN_ON(!q_chip)) |
| 646 | return -ENODEV; |
| 647 | |
| 648 | q_spec = qpnp_chip_gpio_get_spec(q_chip, offset); |
| 649 | if (WARN_ON(!q_spec)) |
| 650 | return -ENODEV; |
| 651 | |
| 652 | /* gpio val is from RT status iff input is enabled */ |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 653 | if ((q_spec->regs[Q_REG_I_MODE_CTL] & Q_REG_MODE_SEL_MASK) |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 654 | == QPNP_PIN_MODE_DIG_IN) { |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 655 | rc = spmi_ext_register_readl(q_chip->spmi->ctrl, q_spec->slave, |
| 656 | Q_REG_ADDR(q_spec, Q_REG_STATUS1), |
| 657 | &buf[0], 1); |
Michael Bohan | ffa1681 | 2012-08-15 18:11:49 -0700 | [diff] [blame] | 658 | |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 659 | if (q_spec->type == Q_GPIO_TYPE && q_spec->dig_major_rev == 0) |
| 660 | en_mask = Q_REG_STATUS1_GPIO_EN_REV0_MASK; |
| 661 | else if (q_spec->type == Q_GPIO_TYPE && |
| 662 | q_spec->dig_major_rev > 0) |
| 663 | en_mask = Q_REG_STATUS1_GPIO_EN_MASK; |
| 664 | else /* MPP */ |
| 665 | en_mask = Q_REG_STATUS1_MPP_EN_MASK; |
| 666 | |
Michael Bohan | ffa1681 | 2012-08-15 18:11:49 -0700 | [diff] [blame] | 667 | if (!(buf[0] & en_mask)) |
| 668 | return -EPERM; |
| 669 | |
| 670 | return buf[0] & Q_REG_STATUS1_VAL_MASK; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 671 | |
| 672 | } else { |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 673 | ret_val = (q_spec->regs[Q_REG_I_MODE_CTL] & |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 674 | Q_REG_OUT_INVERT_MASK) >> Q_REG_OUT_INVERT_SHIFT; |
| 675 | return ret_val; |
| 676 | } |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 681 | static int __qpnp_pin_set(struct qpnp_pin_chip *q_chip, |
| 682 | struct qpnp_pin_spec *q_spec, int value) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 683 | { |
| 684 | int rc; |
| 685 | |
| 686 | if (!q_chip || !q_spec) |
| 687 | return -EINVAL; |
| 688 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 689 | if (value) |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 690 | q_reg_clr_set(&q_spec->regs[Q_REG_I_MODE_CTL], |
| 691 | Q_REG_OUT_INVERT_SHIFT, Q_REG_OUT_INVERT_MASK, 1); |
| 692 | else |
| 693 | q_reg_clr_set(&q_spec->regs[Q_REG_I_MODE_CTL], |
| 694 | Q_REG_OUT_INVERT_SHIFT, Q_REG_OUT_INVERT_MASK, 0); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 695 | |
| 696 | rc = spmi_ext_register_writel(q_chip->spmi->ctrl, q_spec->slave, |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 697 | Q_REG_ADDR(q_spec, Q_REG_MODE_CTL), |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 698 | &q_spec->regs[Q_REG_I_MODE_CTL], 1); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 699 | if (rc) |
| 700 | dev_err(&q_chip->spmi->dev, "%s: spmi write failed\n", |
| 701 | __func__); |
| 702 | return rc; |
| 703 | } |
| 704 | |
| 705 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 706 | static void qpnp_pin_set(struct gpio_chip *gpio_chip, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 707 | unsigned offset, int value) |
| 708 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 709 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(gpio_chip->dev); |
| 710 | struct qpnp_pin_spec *q_spec; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 711 | |
| 712 | if (WARN_ON(!q_chip)) |
| 713 | return; |
| 714 | |
| 715 | q_spec = qpnp_chip_gpio_get_spec(q_chip, offset); |
| 716 | if (WARN_ON(!q_spec)) |
| 717 | return; |
| 718 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 719 | __qpnp_pin_set(q_chip, q_spec, value); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 720 | } |
| 721 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 722 | static int qpnp_pin_set_mode(struct qpnp_pin_chip *q_chip, |
| 723 | struct qpnp_pin_spec *q_spec, int mode) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 724 | { |
| 725 | int rc; |
| 726 | |
| 727 | if (!q_chip || !q_spec) |
| 728 | return -EINVAL; |
| 729 | |
Michael Bohan | 1c3d94f | 2012-08-11 14:33:03 -0700 | [diff] [blame] | 730 | if (qpnp_pin_check_config(Q_PIN_CFG_MODE, q_spec, mode)) { |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 731 | pr_err("invalid mode specification %d\n", mode); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 732 | return -EINVAL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 735 | q_reg_clr_set(&q_spec->regs[Q_REG_I_MODE_CTL], |
| 736 | Q_REG_MODE_SEL_SHIFT, |
| 737 | Q_REG_MODE_SEL_MASK, |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 738 | mode); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 739 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 740 | rc = spmi_ext_register_writel(q_chip->spmi->ctrl, q_spec->slave, |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 741 | Q_REG_ADDR(q_spec, Q_REG_MODE_CTL), |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 742 | &q_spec->regs[Q_REG_I_MODE_CTL], 1); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 743 | return rc; |
| 744 | } |
| 745 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 746 | static int qpnp_pin_direction_input(struct gpio_chip *gpio_chip, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 747 | unsigned offset) |
| 748 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 749 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(gpio_chip->dev); |
| 750 | struct qpnp_pin_spec *q_spec; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 751 | |
| 752 | if (WARN_ON(!q_chip)) |
| 753 | return -ENODEV; |
| 754 | |
| 755 | q_spec = qpnp_chip_gpio_get_spec(q_chip, offset); |
| 756 | if (WARN_ON(!q_spec)) |
| 757 | return -ENODEV; |
| 758 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 759 | return qpnp_pin_set_mode(q_chip, q_spec, QPNP_PIN_MODE_DIG_IN); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 762 | static int qpnp_pin_direction_output(struct gpio_chip *gpio_chip, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 763 | unsigned offset, |
| 764 | int val) |
| 765 | { |
| 766 | int rc; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 767 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(gpio_chip->dev); |
| 768 | struct qpnp_pin_spec *q_spec; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 769 | |
| 770 | if (WARN_ON(!q_chip)) |
| 771 | return -ENODEV; |
| 772 | |
| 773 | q_spec = qpnp_chip_gpio_get_spec(q_chip, offset); |
| 774 | if (WARN_ON(!q_spec)) |
| 775 | return -ENODEV; |
| 776 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 777 | rc = __qpnp_pin_set(q_chip, q_spec, val); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 778 | if (rc) |
| 779 | return rc; |
| 780 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 781 | rc = qpnp_pin_set_mode(q_chip, q_spec, QPNP_PIN_MODE_DIG_OUT); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 782 | |
| 783 | return rc; |
| 784 | } |
| 785 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 786 | static int qpnp_pin_of_gpio_xlate(struct gpio_chip *gpio_chip, |
Michael Bohan | 0b24fb1 | 2012-06-01 10:30:12 -0700 | [diff] [blame] | 787 | const struct of_phandle_args *gpio_spec, |
| 788 | u32 *flags) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 789 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 790 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(gpio_chip->dev); |
| 791 | struct qpnp_pin_spec *q_spec; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 792 | |
| 793 | if (WARN_ON(gpio_chip->of_gpio_n_cells < 2)) { |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 794 | pr_err("of_gpio_n_cells < 2\n"); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 795 | return -EINVAL; |
| 796 | } |
| 797 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 798 | q_spec = qpnp_pmic_pin_get_spec(q_chip, gpio_spec->args[0]); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 799 | if (!q_spec) { |
Michael Bohan | 0b24fb1 | 2012-06-01 10:30:12 -0700 | [diff] [blame] | 800 | pr_err("no such PMIC gpio %u in device topology\n", |
| 801 | gpio_spec->args[0]); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 802 | return -EINVAL; |
| 803 | } |
| 804 | |
| 805 | if (flags) |
Michael Bohan | 0b24fb1 | 2012-06-01 10:30:12 -0700 | [diff] [blame] | 806 | *flags = gpio_spec->args[1]; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 807 | |
| 808 | return q_spec->gpio_chip_idx; |
| 809 | } |
| 810 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 811 | static int qpnp_pin_apply_config(struct qpnp_pin_chip *q_chip, |
| 812 | struct qpnp_pin_spec *q_spec) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 813 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 814 | struct qpnp_pin_cfg param; |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 815 | struct device_node *node = q_spec->node; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 816 | int rc; |
| 817 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 818 | param.mode = q_reg_get(&q_spec->regs[Q_REG_I_MODE_CTL], |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 819 | Q_REG_MODE_SEL_SHIFT, |
| 820 | Q_REG_MODE_SEL_MASK); |
| 821 | param.output_type = q_reg_get(&q_spec->regs[Q_REG_I_DIG_OUT_CTL], |
| 822 | Q_REG_OUT_TYPE_SHIFT, |
| 823 | Q_REG_OUT_TYPE_MASK); |
| 824 | param.invert = q_reg_get(&q_spec->regs[Q_REG_I_MODE_CTL], |
Michael Bohan | d3cf9b0 | 2012-08-15 23:23:52 -0700 | [diff] [blame] | 825 | Q_REG_OUT_INVERT_SHIFT, |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 826 | Q_REG_OUT_INVERT_MASK); |
Michael Bohan | 26324a2 | 2013-03-20 10:15:33 -0700 | [diff] [blame] | 827 | param.pull = q_reg_get(&q_spec->regs[Q_REG_I_DIG_PULL_CTL], |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 828 | Q_REG_PULL_SHIFT, Q_REG_PULL_MASK); |
| 829 | param.vin_sel = q_reg_get(&q_spec->regs[Q_REG_I_DIG_VIN_CTL], |
| 830 | Q_REG_VIN_SHIFT, Q_REG_VIN_MASK); |
| 831 | param.out_strength = q_reg_get(&q_spec->regs[Q_REG_I_DIG_OUT_CTL], |
| 832 | Q_REG_OUT_STRENGTH_SHIFT, |
| 833 | Q_REG_OUT_STRENGTH_MASK); |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 834 | param.src_sel = q_reg_get(&q_spec->regs[Q_REG_I_MODE_CTL], |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 835 | Q_REG_SRC_SEL_SHIFT, Q_REG_SRC_SEL_MASK); |
| 836 | param.master_en = q_reg_get(&q_spec->regs[Q_REG_I_EN_CTL], |
| 837 | Q_REG_MASTER_EN_SHIFT, |
| 838 | Q_REG_MASTER_EN_MASK); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 839 | param.aout_ref = q_reg_get(&q_spec->regs[Q_REG_I_AOUT_CTL], |
| 840 | Q_REG_AOUT_REF_SHIFT, |
| 841 | Q_REG_AOUT_REF_MASK); |
| 842 | param.ain_route = q_reg_get(&q_spec->regs[Q_REG_I_AIN_CTL], |
| 843 | Q_REG_AIN_ROUTE_SHIFT, |
| 844 | Q_REG_AIN_ROUTE_MASK); |
| 845 | param.cs_out = q_reg_get(&q_spec->regs[Q_REG_I_SINK_CTL], |
| 846 | Q_REG_CS_OUT_SHIFT, |
| 847 | Q_REG_CS_OUT_MASK); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 848 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 849 | of_property_read_u32(node, "qcom,mode", |
| 850 | ¶m.mode); |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 851 | of_property_read_u32(node, "qcom,output-type", |
| 852 | ¶m.output_type); |
| 853 | of_property_read_u32(node, "qcom,invert", |
| 854 | ¶m.invert); |
| 855 | of_property_read_u32(node, "qcom,pull", |
| 856 | ¶m.pull); |
| 857 | of_property_read_u32(node, "qcom,vin-sel", |
| 858 | ¶m.vin_sel); |
| 859 | of_property_read_u32(node, "qcom,out-strength", |
| 860 | ¶m.out_strength); |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 861 | of_property_read_u32(node, "qcom,src-sel", |
| 862 | ¶m.src_sel); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 863 | of_property_read_u32(node, "qcom,master-en", |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 864 | ¶m.master_en); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 865 | of_property_read_u32(node, "qcom,aout-ref", |
| 866 | ¶m.aout_ref); |
| 867 | of_property_read_u32(node, "qcom,ain-route", |
| 868 | ¶m.ain_route); |
| 869 | of_property_read_u32(node, "qcom,cs-out", |
| 870 | ¶m.cs_out); |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 871 | rc = _qpnp_pin_config(q_chip, q_spec, ¶m); |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 872 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 873 | return rc; |
| 874 | } |
| 875 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 876 | static int qpnp_pin_free_chip(struct qpnp_pin_chip *q_chip) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 877 | { |
| 878 | struct spmi_device *spmi = q_chip->spmi; |
| 879 | int rc, i; |
| 880 | |
| 881 | if (q_chip->chip_gpios) |
| 882 | for (i = 0; i < spmi->num_dev_node; i++) |
| 883 | kfree(q_chip->chip_gpios[i]); |
| 884 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 885 | mutex_lock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 886 | list_del(&q_chip->chip_list); |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 887 | mutex_unlock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 888 | rc = gpiochip_remove(&q_chip->gpio_chip); |
| 889 | if (rc) |
| 890 | dev_err(&q_chip->spmi->dev, "%s: unable to remove gpio\n", |
| 891 | __func__); |
| 892 | kfree(q_chip->chip_gpios); |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 893 | kfree(q_chip->pmic_pins); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 894 | kfree(q_chip); |
| 895 | return rc; |
| 896 | } |
| 897 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 898 | #ifdef CONFIG_GPIO_QPNP_PIN_DEBUG |
| 899 | struct qpnp_pin_reg { |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 900 | uint32_t addr; |
| 901 | uint32_t idx; |
| 902 | uint32_t shift; |
| 903 | uint32_t mask; |
| 904 | }; |
| 905 | |
| 906 | static struct dentry *driver_dfs_dir; |
| 907 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 908 | static int qpnp_pin_reg_attr(enum qpnp_pin_param_type type, |
| 909 | struct qpnp_pin_reg *cfg) |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 910 | { |
| 911 | switch (type) { |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 912 | case Q_PIN_CFG_MODE: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 913 | cfg->addr = Q_REG_MODE_CTL; |
| 914 | cfg->idx = Q_REG_I_MODE_CTL; |
| 915 | cfg->shift = Q_REG_MODE_SEL_SHIFT; |
| 916 | cfg->mask = Q_REG_MODE_SEL_MASK; |
| 917 | break; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 918 | case Q_PIN_CFG_OUTPUT_TYPE: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 919 | cfg->addr = Q_REG_DIG_OUT_CTL; |
| 920 | cfg->idx = Q_REG_I_DIG_OUT_CTL; |
| 921 | cfg->shift = Q_REG_OUT_TYPE_SHIFT; |
| 922 | cfg->mask = Q_REG_OUT_TYPE_MASK; |
| 923 | break; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 924 | case Q_PIN_CFG_INVERT: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 925 | cfg->addr = Q_REG_MODE_CTL; |
| 926 | cfg->idx = Q_REG_I_MODE_CTL; |
| 927 | cfg->shift = Q_REG_OUT_INVERT_SHIFT; |
| 928 | cfg->mask = Q_REG_OUT_INVERT_MASK; |
| 929 | break; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 930 | case Q_PIN_CFG_PULL: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 931 | cfg->addr = Q_REG_DIG_PULL_CTL; |
| 932 | cfg->idx = Q_REG_I_DIG_PULL_CTL; |
| 933 | cfg->shift = Q_REG_PULL_SHIFT; |
| 934 | cfg->mask = Q_REG_PULL_MASK; |
| 935 | break; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 936 | case Q_PIN_CFG_VIN_SEL: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 937 | cfg->addr = Q_REG_DIG_VIN_CTL; |
| 938 | cfg->idx = Q_REG_I_DIG_VIN_CTL; |
| 939 | cfg->shift = Q_REG_VIN_SHIFT; |
| 940 | cfg->mask = Q_REG_VIN_MASK; |
| 941 | break; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 942 | case Q_PIN_CFG_OUT_STRENGTH: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 943 | cfg->addr = Q_REG_DIG_OUT_CTL; |
| 944 | cfg->idx = Q_REG_I_DIG_OUT_CTL; |
| 945 | cfg->shift = Q_REG_OUT_STRENGTH_SHIFT; |
| 946 | cfg->mask = Q_REG_OUT_STRENGTH_MASK; |
| 947 | break; |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 948 | case Q_PIN_CFG_SRC_SEL: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 949 | cfg->addr = Q_REG_MODE_CTL; |
| 950 | cfg->idx = Q_REG_I_MODE_CTL; |
| 951 | cfg->shift = Q_REG_SRC_SEL_SHIFT; |
| 952 | cfg->mask = Q_REG_SRC_SEL_MASK; |
| 953 | break; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 954 | case Q_PIN_CFG_MASTER_EN: |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 955 | cfg->addr = Q_REG_EN_CTL; |
| 956 | cfg->idx = Q_REG_I_EN_CTL; |
| 957 | cfg->shift = Q_REG_MASTER_EN_SHIFT; |
| 958 | cfg->mask = Q_REG_MASTER_EN_MASK; |
| 959 | break; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 960 | case Q_PIN_CFG_AOUT_REF: |
| 961 | cfg->addr = Q_REG_AOUT_CTL; |
| 962 | cfg->idx = Q_REG_I_AOUT_CTL; |
| 963 | cfg->shift = Q_REG_AOUT_REF_SHIFT; |
| 964 | cfg->mask = Q_REG_AOUT_REF_MASK; |
| 965 | break; |
| 966 | case Q_PIN_CFG_AIN_ROUTE: |
| 967 | cfg->addr = Q_REG_AIN_CTL; |
| 968 | cfg->idx = Q_REG_I_AIN_CTL; |
| 969 | cfg->shift = Q_REG_AIN_ROUTE_SHIFT; |
| 970 | cfg->mask = Q_REG_AIN_ROUTE_MASK; |
| 971 | break; |
| 972 | case Q_PIN_CFG_CS_OUT: |
| 973 | cfg->addr = Q_REG_SINK_CTL; |
| 974 | cfg->idx = Q_REG_I_SINK_CTL; |
| 975 | cfg->shift = Q_REG_CS_OUT_SHIFT; |
| 976 | cfg->mask = Q_REG_CS_OUT_MASK; |
| 977 | break; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 978 | default: |
| 979 | return -EINVAL; |
| 980 | } |
| 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 985 | static int qpnp_pin_debugfs_get(void *data, u64 *val) |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 986 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 987 | enum qpnp_pin_param_type *idx = data; |
| 988 | struct qpnp_pin_spec *q_spec; |
| 989 | struct qpnp_pin_reg cfg = {}; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 990 | int rc; |
| 991 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 992 | rc = qpnp_pin_reg_attr(*idx, &cfg); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 993 | if (rc) |
| 994 | return rc; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 995 | q_spec = container_of(idx, struct qpnp_pin_spec, params[*idx]); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 996 | *val = q_reg_get(&q_spec->regs[cfg.idx], cfg.shift, cfg.mask); |
| 997 | return 0; |
| 998 | } |
| 999 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1000 | static int qpnp_pin_debugfs_set(void *data, u64 val) |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1001 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1002 | enum qpnp_pin_param_type *idx = data; |
| 1003 | struct qpnp_pin_spec *q_spec; |
| 1004 | struct qpnp_pin_chip *q_chip; |
| 1005 | struct qpnp_pin_reg cfg = {}; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1006 | int rc; |
| 1007 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1008 | q_spec = container_of(idx, struct qpnp_pin_spec, params[*idx]); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1009 | q_chip = q_spec->q_chip; |
| 1010 | |
Michael Bohan | 58d0780 | 2012-05-31 15:37:55 -0700 | [diff] [blame] | 1011 | rc = qpnp_pin_check_config(*idx, q_spec, val); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1012 | if (rc) |
| 1013 | return rc; |
| 1014 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1015 | rc = qpnp_pin_reg_attr(*idx, &cfg); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1016 | if (rc) |
| 1017 | return rc; |
| 1018 | q_reg_clr_set(&q_spec->regs[cfg.idx], cfg.shift, cfg.mask, val); |
| 1019 | rc = spmi_ext_register_writel(q_chip->spmi->ctrl, q_spec->slave, |
| 1020 | Q_REG_ADDR(q_spec, cfg.addr), |
| 1021 | &q_spec->regs[cfg.idx], 1); |
| 1022 | |
| 1023 | return rc; |
| 1024 | } |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1025 | DEFINE_SIMPLE_ATTRIBUTE(qpnp_pin_fops, qpnp_pin_debugfs_get, |
| 1026 | qpnp_pin_debugfs_set, "%llu\n"); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1027 | |
| 1028 | #define DEBUGFS_BUF_SIZE 11 /* supports 2^32 in decimal */ |
| 1029 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1030 | struct qpnp_pin_debugfs_args { |
| 1031 | enum qpnp_pin_param_type type; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1032 | const char *filename; |
| 1033 | }; |
| 1034 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1035 | static struct qpnp_pin_debugfs_args dfs_args[] = { |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 1036 | { Q_PIN_CFG_MODE, "mode" }, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1037 | { Q_PIN_CFG_OUTPUT_TYPE, "output_type" }, |
| 1038 | { Q_PIN_CFG_INVERT, "invert" }, |
| 1039 | { Q_PIN_CFG_PULL, "pull" }, |
| 1040 | { Q_PIN_CFG_VIN_SEL, "vin_sel" }, |
| 1041 | { Q_PIN_CFG_OUT_STRENGTH, "out_strength" }, |
Michael Bohan | d734fb2 | 2012-10-30 14:19:22 -0700 | [diff] [blame] | 1042 | { Q_PIN_CFG_SRC_SEL, "src_sel" }, |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 1043 | { Q_PIN_CFG_MASTER_EN, "master_en" }, |
| 1044 | { Q_PIN_CFG_AOUT_REF, "aout_ref" }, |
| 1045 | { Q_PIN_CFG_AIN_ROUTE, "ain_route" }, |
| 1046 | { Q_PIN_CFG_CS_OUT, "cs_out" }, |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1047 | }; |
| 1048 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1049 | static int qpnp_pin_debugfs_create(struct qpnp_pin_chip *q_chip) |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1050 | { |
| 1051 | struct spmi_device *spmi = q_chip->spmi; |
| 1052 | struct device *dev = &spmi->dev; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1053 | struct qpnp_pin_spec *q_spec; |
| 1054 | enum qpnp_pin_param_type *params; |
| 1055 | enum qpnp_pin_param_type type; |
| 1056 | char pmic_pin[DEBUGFS_BUF_SIZE]; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1057 | const char *filename; |
| 1058 | struct dentry *dfs, *dfs_io_dir; |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 1059 | int i, j, rc; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1060 | |
| 1061 | BUG_ON(Q_NUM_PARAMS != ARRAY_SIZE(dfs_args)); |
| 1062 | |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1063 | q_chip->dfs_dir = debugfs_create_dir(q_chip->gpio_chip.label, |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1064 | driver_dfs_dir); |
| 1065 | if (q_chip->dfs_dir == NULL) { |
| 1066 | dev_err(dev, "%s: cannot register chip debugfs directory %s\n", |
| 1067 | __func__, dev->of_node->name); |
| 1068 | return -ENODEV; |
| 1069 | } |
| 1070 | |
| 1071 | for (i = 0; i < spmi->num_dev_node; i++) { |
| 1072 | q_spec = qpnp_chip_gpio_get_spec(q_chip, i); |
| 1073 | params = q_spec->params; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1074 | snprintf(pmic_pin, DEBUGFS_BUF_SIZE, "%u", q_spec->pmic_pin); |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 1075 | dfs_io_dir = debugfs_create_dir(pmic_pin, q_chip->dfs_dir); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1076 | if (dfs_io_dir == NULL) |
| 1077 | goto dfs_err; |
| 1078 | |
| 1079 | for (j = 0; j < Q_NUM_PARAMS; j++) { |
| 1080 | type = dfs_args[j].type; |
| 1081 | filename = dfs_args[j].filename; |
| 1082 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 1083 | /* |
| 1084 | * Use a value of '0' to see if the pin has even basic |
| 1085 | * support for a function. Do not create a file if |
| 1086 | * it doesn't. |
| 1087 | */ |
| 1088 | rc = qpnp_pin_check_config(type, q_spec, 0); |
| 1089 | if (rc == -ENXIO) |
| 1090 | continue; |
| 1091 | |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1092 | params[type] = type; |
| 1093 | dfs = debugfs_create_file( |
| 1094 | filename, |
| 1095 | S_IRUGO | S_IWUSR, |
| 1096 | dfs_io_dir, |
| 1097 | &q_spec->params[type], |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1098 | &qpnp_pin_fops); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1099 | if (dfs == NULL) |
| 1100 | goto dfs_err; |
| 1101 | } |
| 1102 | } |
| 1103 | return 0; |
| 1104 | dfs_err: |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1105 | dev_err(dev, "%s: cannot register debugfs for pmic gpio %u on chip %s\n", |
| 1106 | __func__, q_spec->pmic_pin, dev->of_node->name); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1107 | debugfs_remove_recursive(q_chip->dfs_dir); |
| 1108 | return -ENFILE; |
| 1109 | } |
| 1110 | #else |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1111 | static int qpnp_pin_debugfs_create(struct qpnp_pin_chip *q_chip) |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1112 | { |
| 1113 | return 0; |
| 1114 | } |
| 1115 | #endif |
| 1116 | |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 1117 | static int qpnp_pin_is_valid_pin(struct qpnp_pin_spec *q_spec) |
| 1118 | { |
| 1119 | if (q_spec->type == Q_GPIO_TYPE) |
| 1120 | switch (q_spec->subtype) { |
| 1121 | case Q_GPIO_SUBTYPE_GPIO_4CH: |
| 1122 | case Q_GPIO_SUBTYPE_GPIOC_4CH: |
| 1123 | case Q_GPIO_SUBTYPE_GPIO_8CH: |
| 1124 | case Q_GPIO_SUBTYPE_GPIOC_8CH: |
| 1125 | return 1; |
| 1126 | } |
| 1127 | else if (q_spec->type == Q_MPP_TYPE) |
| 1128 | switch (q_spec->subtype) { |
| 1129 | case Q_MPP_SUBTYPE_4CH_NO_ANA_OUT: |
| 1130 | case Q_MPP_SUBTYPE_4CH_NO_SINK: |
| 1131 | case Q_MPP_SUBTYPE_4CH_FULL_FUNC: |
| 1132 | case Q_MPP_SUBTYPE_8CH_FULL_FUNC: |
| 1133 | return 1; |
| 1134 | } |
| 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1139 | static int qpnp_pin_probe(struct spmi_device *spmi) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1140 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1141 | struct qpnp_pin_chip *q_chip; |
| 1142 | struct qpnp_pin_spec *q_spec; |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame] | 1143 | struct resource *res; |
| 1144 | struct spmi_resource *d_node; |
Michael Bohan | 94e397b | 2012-04-25 15:21:55 -0700 | [diff] [blame] | 1145 | int i, rc; |
| 1146 | int lowest_gpio = UINT_MAX, highest_gpio = 0; |
| 1147 | u32 intspec[3], gpio; |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 1148 | char version[Q_REG_SUBTYPE - Q_REG_DIG_MAJOR_REV + 1]; |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1149 | const char *dev_name; |
| 1150 | |
| 1151 | dev_name = spmi_get_primary_dev_name(spmi); |
| 1152 | if (!dev_name) { |
| 1153 | dev_err(&spmi->dev, "%s: label binding undefined for node %s\n", |
| 1154 | __func__, spmi->dev.of_node->full_name); |
| 1155 | return -EINVAL; |
| 1156 | } |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1157 | |
| 1158 | q_chip = kzalloc(sizeof(*q_chip), GFP_KERNEL); |
| 1159 | if (!q_chip) { |
| 1160 | dev_err(&spmi->dev, "%s: Can't allocate gpio_chip\n", |
| 1161 | __func__); |
| 1162 | return -ENOMEM; |
| 1163 | } |
| 1164 | q_chip->spmi = spmi; |
| 1165 | dev_set_drvdata(&spmi->dev, q_chip); |
| 1166 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1167 | mutex_lock(&qpnp_pin_chips_lock); |
| 1168 | list_add(&q_chip->chip_list, &qpnp_pin_chips); |
| 1169 | mutex_unlock(&qpnp_pin_chips_lock); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1170 | |
| 1171 | /* first scan through nodes to find the range required for allocation */ |
| 1172 | for (i = 0; i < spmi->num_dev_node; i++) { |
Michael Bohan | 94e397b | 2012-04-25 15:21:55 -0700 | [diff] [blame] | 1173 | rc = of_property_read_u32(spmi->dev_node[i].of_node, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1174 | "qcom,pin-num", &gpio); |
Michael Bohan | 94e397b | 2012-04-25 15:21:55 -0700 | [diff] [blame] | 1175 | if (rc) { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1176 | dev_err(&spmi->dev, "%s: unable to get qcom,pin-num property\n", |
| 1177 | __func__); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1178 | goto err_probe; |
| 1179 | } |
| 1180 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1181 | if (gpio < lowest_gpio) |
| 1182 | lowest_gpio = gpio; |
| 1183 | if (gpio > highest_gpio) |
| 1184 | highest_gpio = gpio; |
| 1185 | } |
| 1186 | |
| 1187 | if (highest_gpio < lowest_gpio) { |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1188 | dev_err(&spmi->dev, "%s: no device nodes specified in topology\n", |
| 1189 | __func__); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1190 | rc = -EINVAL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1191 | goto err_probe; |
| 1192 | } else if (lowest_gpio == 0) { |
| 1193 | dev_err(&spmi->dev, "%s: 0 is not a valid PMIC GPIO\n", |
| 1194 | __func__); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1195 | rc = -EINVAL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1196 | goto err_probe; |
| 1197 | } |
| 1198 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1199 | q_chip->pmic_pin_lowest = lowest_gpio; |
| 1200 | q_chip->pmic_pin_highest = highest_gpio; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1201 | |
| 1202 | /* allocate gpio lookup tables */ |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1203 | q_chip->pmic_pins = kzalloc(sizeof(struct qpnp_pin_spec *) * |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1204 | highest_gpio - lowest_gpio + 1, |
| 1205 | GFP_KERNEL); |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1206 | q_chip->chip_gpios = kzalloc(sizeof(struct qpnp_pin_spec *) * |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1207 | spmi->num_dev_node, GFP_KERNEL); |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1208 | if (!q_chip->pmic_pins || !q_chip->chip_gpios) { |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1209 | dev_err(&spmi->dev, "%s: unable to allocate memory\n", |
| 1210 | __func__); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1211 | rc = -ENOMEM; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1212 | goto err_probe; |
| 1213 | } |
| 1214 | |
| 1215 | /* get interrupt controller device_node */ |
| 1216 | q_chip->int_ctrl = of_irq_find_parent(spmi->dev.of_node); |
| 1217 | if (!q_chip->int_ctrl) { |
| 1218 | dev_err(&spmi->dev, "%s: Can't find interrupt parent\n", |
| 1219 | __func__); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1220 | rc = -EINVAL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1221 | goto err_probe; |
| 1222 | } |
| 1223 | |
| 1224 | /* now scan through again and populate the lookup table */ |
| 1225 | for (i = 0; i < spmi->num_dev_node; i++) { |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame] | 1226 | d_node = &spmi->dev_node[i]; |
| 1227 | res = spmi_get_resource(spmi, d_node, IORESOURCE_MEM, 0); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1228 | if (!res) { |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1229 | dev_err(&spmi->dev, "%s: node %s is missing has no base address definition\n", |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame] | 1230 | __func__, d_node->of_node->full_name); |
Zhenhua Huang | 30acf24 | 2013-07-11 01:52:36 +0800 | [diff] [blame] | 1231 | rc = -EINVAL; |
| 1232 | goto err_probe; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame] | 1235 | rc = of_property_read_u32(d_node->of_node, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1236 | "qcom,pin-num", &gpio); |
Michael Bohan | 94e397b | 2012-04-25 15:21:55 -0700 | [diff] [blame] | 1237 | if (rc) { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1238 | dev_err(&spmi->dev, "%s: unable to get qcom,pin-num property\n", |
| 1239 | __func__); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1240 | goto err_probe; |
| 1241 | } |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1242 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1243 | q_spec = kzalloc(sizeof(struct qpnp_pin_spec), |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1244 | GFP_KERNEL); |
| 1245 | if (!q_spec) { |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1246 | dev_err(&spmi->dev, "%s: unable to allocate memory\n", |
| 1247 | __func__); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1248 | rc = -ENOMEM; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1249 | goto err_probe; |
| 1250 | } |
| 1251 | |
| 1252 | q_spec->slave = spmi->sid; |
| 1253 | q_spec->offset = res->start; |
| 1254 | q_spec->gpio_chip_idx = i; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1255 | q_spec->pmic_pin = gpio; |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame] | 1256 | q_spec->node = d_node->of_node; |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1257 | q_spec->q_chip = q_chip; |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 1258 | |
| 1259 | rc = spmi_ext_register_readl(spmi->ctrl, q_spec->slave, |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 1260 | Q_REG_ADDR(q_spec, Q_REG_DIG_MAJOR_REV), |
| 1261 | &version[0], ARRAY_SIZE(version)); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 1262 | if (rc) { |
| 1263 | dev_err(&spmi->dev, "%s: unable to read type regs\n", |
| 1264 | __func__); |
Michael Bohan | e25e15f | 2012-04-12 17:28:26 -0700 | [diff] [blame] | 1265 | goto err_probe; |
| 1266 | } |
Michael Bohan | bfe64c7 | 2012-08-24 16:57:26 -0700 | [diff] [blame] | 1267 | q_spec->dig_major_rev = version[Q_REG_DIG_MAJOR_REV - |
| 1268 | Q_REG_DIG_MAJOR_REV]; |
| 1269 | q_spec->type = version[Q_REG_TYPE - Q_REG_DIG_MAJOR_REV]; |
| 1270 | q_spec->subtype = version[Q_REG_SUBTYPE - Q_REG_DIG_MAJOR_REV]; |
| 1271 | |
| 1272 | if (!qpnp_pin_is_valid_pin(q_spec)) { |
| 1273 | dev_err(&spmi->dev, "%s: invalid pin type (type=0x%x subtype=0x%x)\n", |
| 1274 | __func__, q_spec->type, q_spec->subtype); |
| 1275 | goto err_probe; |
| 1276 | } |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1277 | |
Michael Bohan | 6b90157 | 2012-05-30 13:32:24 -0700 | [diff] [blame] | 1278 | rc = qpnp_pin_ctl_regs_init(q_spec); |
| 1279 | if (rc) |
| 1280 | goto err_probe; |
| 1281 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1282 | /* call into irq_domain to get irq mapping */ |
| 1283 | intspec[0] = q_chip->spmi->sid; |
| 1284 | intspec[1] = (q_spec->offset >> 8) & 0xFF; |
| 1285 | intspec[2] = 0; |
| 1286 | q_spec->irq = irq_create_of_mapping(q_chip->int_ctrl, |
| 1287 | intspec, 3); |
| 1288 | if (!q_spec->irq) { |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1289 | dev_err(&spmi->dev, "%s: invalid irq for gpio %u\n", |
| 1290 | __func__, gpio); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1291 | rc = -EINVAL; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1292 | goto err_probe; |
| 1293 | } |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1294 | /* initialize lookup table params */ |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1295 | qpnp_pmic_pin_set_spec(q_chip, gpio, q_spec); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1296 | qpnp_chip_gpio_set_spec(q_chip, i, q_spec); |
| 1297 | } |
| 1298 | |
| 1299 | q_chip->gpio_chip.base = -1; |
| 1300 | q_chip->gpio_chip.ngpio = spmi->num_dev_node; |
Michael Bohan | 6ea2cd2 | 2012-05-29 15:40:18 -0700 | [diff] [blame] | 1301 | q_chip->gpio_chip.label = dev_name; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1302 | q_chip->gpio_chip.direction_input = qpnp_pin_direction_input; |
| 1303 | q_chip->gpio_chip.direction_output = qpnp_pin_direction_output; |
| 1304 | q_chip->gpio_chip.to_irq = qpnp_pin_to_irq; |
| 1305 | q_chip->gpio_chip.get = qpnp_pin_get; |
| 1306 | q_chip->gpio_chip.set = qpnp_pin_set; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1307 | q_chip->gpio_chip.dev = &spmi->dev; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1308 | q_chip->gpio_chip.of_xlate = qpnp_pin_of_gpio_xlate; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1309 | q_chip->gpio_chip.of_gpio_n_cells = 2; |
| 1310 | q_chip->gpio_chip.can_sleep = 0; |
| 1311 | |
| 1312 | rc = gpiochip_add(&q_chip->gpio_chip); |
| 1313 | if (rc) { |
| 1314 | dev_err(&spmi->dev, "%s: Can't add gpio chip, rc = %d\n", |
| 1315 | __func__, rc); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1316 | goto err_probe; |
| 1317 | } |
| 1318 | |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 1319 | /* now configure gpio config defaults if they exist */ |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1320 | for (i = 0; i < spmi->num_dev_node; i++) { |
| 1321 | q_spec = qpnp_chip_gpio_get_spec(q_chip, i); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1322 | if (WARN_ON(!q_spec)) { |
| 1323 | rc = -ENODEV; |
| 1324 | goto err_probe; |
| 1325 | } |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1326 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1327 | rc = qpnp_pin_cache_regs(q_chip, q_spec); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1328 | if (rc) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1329 | goto err_probe; |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 1330 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1331 | rc = qpnp_pin_apply_config(q_chip, q_spec); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1332 | if (rc) |
Michael Bohan | de3942a | 2012-04-17 15:28:01 -0700 | [diff] [blame] | 1333 | goto err_probe; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | dev_dbg(&spmi->dev, "%s: gpio_chip registered between %d-%u\n", |
| 1337 | __func__, q_chip->gpio_chip.base, |
| 1338 | (q_chip->gpio_chip.base + q_chip->gpio_chip.ngpio) - 1); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1339 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1340 | rc = qpnp_pin_debugfs_create(q_chip); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1341 | if (rc) { |
| 1342 | dev_err(&spmi->dev, "%s: debugfs creation failed\n", __func__); |
| 1343 | goto err_probe; |
| 1344 | } |
| 1345 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1346 | return 0; |
| 1347 | |
| 1348 | err_probe: |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1349 | qpnp_pin_free_chip(q_chip); |
Michael Bohan | fdcbed2 | 2012-04-23 17:44:27 -0700 | [diff] [blame] | 1350 | return rc; |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1353 | static int qpnp_pin_remove(struct spmi_device *spmi) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1354 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1355 | struct qpnp_pin_chip *q_chip = dev_get_drvdata(&spmi->dev); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1356 | |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1357 | debugfs_remove_recursive(q_chip->dfs_dir); |
| 1358 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1359 | return qpnp_pin_free_chip(q_chip); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | static struct of_device_id spmi_match_table[] = { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1363 | { .compatible = "qcom,qpnp-pin", |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1364 | }, |
| 1365 | {} |
| 1366 | }; |
| 1367 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1368 | static const struct spmi_device_id qpnp_pin_id[] = { |
| 1369 | { "qcom,qpnp-pin", 0 }, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1370 | { } |
| 1371 | }; |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1372 | MODULE_DEVICE_TABLE(spmi, qpnp_pin_id); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1373 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1374 | static struct spmi_driver qpnp_pin_driver = { |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1375 | .driver = { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1376 | .name = "qcom,qpnp-pin", |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1377 | .of_match_table = spmi_match_table, |
| 1378 | }, |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1379 | .probe = qpnp_pin_probe, |
| 1380 | .remove = qpnp_pin_remove, |
| 1381 | .id_table = qpnp_pin_id, |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1382 | }; |
| 1383 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1384 | static int __init qpnp_pin_init(void) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1385 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1386 | #ifdef CONFIG_GPIO_QPNP_PIN_DEBUG |
| 1387 | driver_dfs_dir = debugfs_create_dir("qpnp_pin", NULL); |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1388 | if (driver_dfs_dir == NULL) |
| 1389 | pr_err("Cannot register top level debugfs directory\n"); |
| 1390 | #endif |
| 1391 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1392 | return spmi_driver_register(&qpnp_pin_driver); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1395 | static void __exit qpnp_pin_exit(void) |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1396 | { |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1397 | #ifdef CONFIG_GPIO_QPNP_PIN_DEBUG |
Michael Bohan | a19dced | 2012-04-24 13:14:50 -0700 | [diff] [blame] | 1398 | debugfs_remove_recursive(driver_dfs_dir); |
| 1399 | #endif |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1400 | spmi_driver_unregister(&qpnp_pin_driver); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1403 | MODULE_DESCRIPTION("QPNP PMIC gpio driver"); |
Michael Bohan | 7f0cc9d | 2012-04-16 17:16:09 -0700 | [diff] [blame] | 1404 | MODULE_LICENSE("GPL v2"); |
Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame] | 1405 | |
Michael Bohan | a05f455 | 2012-05-24 15:58:11 -0700 | [diff] [blame] | 1406 | module_init(qpnp_pin_init); |
| 1407 | module_exit(qpnp_pin_exit); |