Michael Bohan | 0ba63b8 | 2012-02-06 13:42:34 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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 | #include <mach/qpnp.h> |
| 14 | |
| 15 | #define QPNP_GPIO_DIR_OUT 1 |
| 16 | #define QPNP_GPIO_DIR_IN 2 |
| 17 | #define QPNP_GPIO_DIR_BOTH (QPNP_GPIO_DIR_OUT | QPNP_GPIO_DIR_IN) |
| 18 | |
| 19 | #define QPNP_GPIO_OUT_BUF_OPEN_DRAIN 1 |
| 20 | #define QPNP_GPIO_OUT_BUF_CMOS 0 |
| 21 | |
| 22 | #define QPNP_GPIO_VIN0 0 |
| 23 | #define QPNP_GPIO_VIN1 1 |
| 24 | #define QPNP_GPIO_VIN2 2 |
| 25 | #define QPNP_GPIO_VIN3 3 |
| 26 | #define QPNP_GPIO_VIN4 4 |
| 27 | #define QPNP_GPIO_VIN5 5 |
| 28 | #define QPNP_GPIO_VIN6 6 |
| 29 | #define QPNP_GPIO_VIN7 7 |
| 30 | |
| 31 | #define QPNP_GPIO_PULL_UP_30 0 |
| 32 | #define QPNP_GPIO_PULL_UP_1P5 1 |
| 33 | #define QPNP_GPIO_PULL_UP_31P5 2 |
| 34 | #define QPNP_GPIO_PULL_UP_1P5_30 3 |
| 35 | #define QPNP_GPIO_PULL_DN 4 |
| 36 | #define QPNP_GPIO_PULL_NO 5 |
| 37 | |
| 38 | #define QPNP_GPIO_OUT_STRENGTH_LOW 1 |
| 39 | #define QPNP_GPIO_OUT_STRENGTH_MED 2 |
| 40 | #define QPNP_GPIO_OUT_STRENGTH_HIGH 3 |
| 41 | |
| 42 | #define QPNP_GPIO_FUNC_NORMAL 0 |
| 43 | #define QPNP_GPIO_FUNC_PAIRED 1 |
| 44 | #define QPNP_GPIO_FUNC_1 2 |
| 45 | #define QPNP_GPIO_FUNC_2 3 |
| 46 | #define QPNP_GPIO_DTEST1 4 |
| 47 | #define QPNP_GPIO_DTEST2 5 |
| 48 | #define QPNP_GPIO_DTEST3 6 |
| 49 | #define QPNP_GPIO_DTEST4 7 |
| 50 | |
| 51 | /** |
| 52 | * struct qpnp_gpio_cfg - structure to specify gpio configurtion values |
| 53 | * @direction: indicates whether the gpio should be input, output, or |
| 54 | * both. Should be of the type QPNP_GPIO_DIR_* |
| 55 | * @output_type: indicates gpio should be configured as CMOS or open |
| 56 | * drain. Should be of the type QPNP_GPIO_OUT_BUF_* |
| 57 | * @output_value: The gpio output value of the gpio line - 0 or 1 |
| 58 | * @pull: Indicates whether a pull up or pull down should be |
| 59 | * applied. If a pullup is required the current strength |
| 60 | * needs to be specified. Current values of 30uA, 1.5uA, |
| 61 | * 31.5uA, 1.5uA with 30uA boost are supported. This value |
| 62 | * should be one of the QPNP_GPIO_PULL_* |
| 63 | * @vin_sel: specifies the voltage level when the output is set to 1. |
| 64 | * For an input gpio specifies the voltage level at which |
| 65 | * the input is interpreted as a logical 1. |
| 66 | * @out_strength: the amount of current supplied for an output gpio, |
| 67 | * should be of the type QPNP_GPIO_STRENGTH_* |
| 68 | * @source_sel: choose alternate function for the gpio. Certain gpios |
| 69 | * can be paired (shorted) with each other. Some gpio pin |
| 70 | * can act as alternate functions. This parameter should |
| 71 | * be of type QPNP_GPIO_FUNC_* |
| 72 | * @inv_int_pol: Invert polarity before feeding the line to the interrupt |
| 73 | * module in pmic. This feature will almost be never used |
| 74 | * since the pm8xxx interrupt block can detect both edges |
| 75 | * and both levels. |
| 76 | * @master_en: 1 = Enable features within the GPIO block based on |
| 77 | * configurations. |
| 78 | * 0 = Completely disable the GPIO block and let the pin |
| 79 | * float with high impedance regardless of other settings. |
| 80 | */ |
| 81 | struct qpnp_gpio_cfg { |
| 82 | int direction; |
| 83 | int output_type; |
| 84 | int output_value; |
| 85 | int pull; |
| 86 | int vin_sel; |
| 87 | int out_strength; |
| 88 | int src_select; |
| 89 | int inv_int_pol; |
| 90 | int master_en; |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * qpnp_gpio_config - Apply gpio configuration for Linux gpio |
| 95 | * @gpio: Linux gpio number to configure. |
| 96 | * @param: parameters to configure. |
| 97 | * |
| 98 | * This routine takes a Linux gpio number that corresponds with a |
| 99 | * PMIC gpio and applies the configuration specified in 'param'. |
| 100 | * This gpio number can be ascertained by of_get_gpio_flags() or |
| 101 | * the qpnp_gpio_map_gpio() API. |
| 102 | */ |
| 103 | int qpnp_gpio_config(int gpio, struct qpnp_gpio_cfg *param); |
| 104 | |
| 105 | /** |
| 106 | * qpnp_gpio_map_gpio - Obtain Linux GPIO number from device spec |
| 107 | * @slave_id: slave_id of the spmi_device for the gpio in question. |
| 108 | * @pmic_gpio: PMIC gpio number to lookup. |
| 109 | * |
| 110 | * This routine is used in legacy configurations that do not support |
| 111 | * Device Tree. If you are using Device Tree, you should not use this. |
| 112 | * For such cases, use of_get_gpio() instead. |
| 113 | */ |
| 114 | int qpnp_gpio_map_gpio(uint16_t slave_id, uint32_t pmic_gpio); |