Shimrit Malichi | d1c7efd | 2015-01-21 08:58:48 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 2 | |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation, Inc. nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <qpnp_led.h> |
| 31 | #include <platform/iomap.h> |
| 32 | #include <pm8x41_wled.h> |
| 33 | |
| 34 | static void qpnp_led_config(struct qpnp_led_data *led) |
| 35 | { |
| 36 | pm8x41_wled_reg_write(RGB_LED_SRC_SEL(led->base), |
| 37 | RGB_LED_SOURCE_VPH_PWR); |
| 38 | pm8x41_wled_reg_write(LPG_PATTERN_CONFIG(led->lpg_base), 0x00); |
| 39 | pm8x41_wled_reg_write(LPG_PWM_SIZE_CLK(led->lpg_base), |
| 40 | PWM_6BIT_1KHZ_CLK); |
| 41 | pm8x41_wled_reg_write(LPG_PWM_FREQ_PREDIV_CLK(led->lpg_base), |
| 42 | PWM_FREQ); |
| 43 | pm8x41_wled_reg_write(LPG_PWM_TYPE_CONFIG(led->lpg_base), 0x00); |
| 44 | pm8x41_wled_reg_write(PWM_VALUE_LSB(led->lpg_base), 0x20); |
| 45 | pm8x41_wled_reg_write(PWM_VALUE_MSB(led->lpg_base), 0x00); |
| 46 | pm8x41_wled_reg_write(PWM_SYNC(led->lpg_base), 0x01); |
| 47 | pm8x41_wled_reg_write(LPG_ENABLE_CONTROL(led->lpg_base), |
| 48 | RGB_LED_ENABLE_PWM); |
| 49 | } |
| 50 | |
| 51 | static int qpnp_led_setup(struct qpnp_led_data *led) |
| 52 | { |
| 53 | uint8_t reg = 0; |
| 54 | |
| 55 | reg = pm8x41_wled_reg_read(RGB_LED_EN_CTL(led->base)); |
| 56 | |
| 57 | switch (led->color_sel) { |
| 58 | case QPNP_LED_RED: |
| 59 | reg |= RGB_LED_ENABLE_RED; |
| 60 | break; |
| 61 | case QPNP_LED_GREEN: |
| 62 | reg |= RGB_LED_ENABLE_GREEN; |
| 63 | break; |
| 64 | case QPNP_LED_BLUE: |
| 65 | reg |= RGB_LED_ENABLE_BLUE; |
| 66 | break; |
| 67 | default: |
| 68 | return -1; |
| 69 | }; |
| 70 | |
| 71 | pm8x41_wled_reg_write(RGB_LED_EN_CTL(led->base), reg); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | void qpnp_led_init(enum qpnp_led_op color, uint16_t led_base_addr, |
| 77 | uint16_t lpg_base_addr) |
| 78 | { |
| 79 | int rc; |
| 80 | struct qpnp_led_data led; |
| 81 | |
| 82 | led.base = led_base_addr; |
| 83 | led.lpg_base = lpg_base_addr; |
| 84 | led.color_sel = color; |
| 85 | |
| 86 | rc = qpnp_led_setup(&led); |
| 87 | if (rc) { |
| 88 | dprintf(INFO, "%s : failed\n", __func__); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | qpnp_led_config(&led); |
| 93 | } |
| 94 | |