Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013, 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 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 <bits.h> |
| 30 | #include <reg.h> |
| 31 | #include <pm8x41_hw.h> |
| 32 | #include <pm8x41_wled.h> |
| 33 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 34 | static uint8_t wled_slave_id; |
| 35 | |
| 36 | static void wled_reg_write(uint32_t addr, uint8_t val) |
| 37 | { |
| 38 | uint32_t new_addr; |
| 39 | if (wled_slave_id) { |
| 40 | new_addr = addr + (wled_slave_id << 16); |
| 41 | REG_WRITE(new_addr, val); |
| 42 | } else { |
| 43 | new_addr = addr + (DEFAULT_SLAVE_ID << 16); |
| 44 | REG_WRITE(new_addr, val); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void pm8x41_wled_config_slave_id(uint8_t slave_id) |
| 49 | { |
| 50 | wled_slave_id = slave_id; |
| 51 | } |
| 52 | |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 53 | void pm8x41_wled_config(struct pm8x41_wled_data *wled_ctrl) { |
| 54 | |
| 55 | if (!wled_ctrl) { |
| 56 | dprintf(CRITICAL, "Error: Invalid WLED data.\n"); |
| 57 | return; |
| 58 | } |
| 59 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 60 | wled_reg_write(PM_WLED_MODULATION_SCHEME, wled_ctrl->mod_scheme); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 61 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 62 | wled_reg_write(PM_WLED_LED1_BRIGHTNESS_LSB, (wled_ctrl->led1_brightness & 0xFF)); |
| 63 | wled_reg_write(PM_WLED_LED1_BRIGHTNESS_MSB, ((wled_ctrl->led1_brightness >> 8) & 0xFF)); |
| 64 | wled_reg_write(PM_WLED_LED2_BRIGHTNESS_LSB, (wled_ctrl->led2_brightness & 0xFF)); |
| 65 | wled_reg_write(PM_WLED_LED2_BRIGHTNESS_MSB, ((wled_ctrl->led2_brightness >> 8) & 0xFF)); |
| 66 | wled_reg_write(PM_WLED_LED3_BRIGHTNESS_LSB, (wled_ctrl->led3_brightness & 0xFF)); |
| 67 | wled_reg_write(PM_WLED_LED3_BRIGHTNESS_MSB, ((wled_ctrl->led3_brightness >> 8) & 0xFF)); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 68 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 69 | wled_reg_write(PM_WLED_MAX_DUTY_CYCLE, wled_ctrl->max_duty_cycle); |
| 70 | wled_reg_write(PM_WLED_OVP, wled_ctrl->ovp); |
| 71 | wled_reg_write(LEDn_FULL_SCALE_CURRENT(1), wled_ctrl->full_current_scale); |
| 72 | wled_reg_write(LEDn_FULL_SCALE_CURRENT(2), wled_ctrl->full_current_scale); |
| 73 | wled_reg_write(LEDn_FULL_SCALE_CURRENT(3), wled_ctrl->full_current_scale); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 74 | |
Zhenhua Huang | d5355cb | 2013-09-04 16:03:01 +0800 | [diff] [blame] | 75 | wled_reg_write(PM_WLED_FDBCK_CONTROL, wled_ctrl->fdbck); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 76 | dprintf(SPEW, "WLED Configuration Success.\n"); |
| 77 | |
| 78 | } |
| 79 | |
| 80 | void pm8x41_wled_sink_control(uint8_t enable) { |
| 81 | |
| 82 | uint8_t value = 0x0; |
| 83 | |
| 84 | if (enable) { |
| 85 | value = PM_WLED_LED1_SINK_MASK | |
| 86 | PM_WLED_LED2_SINK_MASK | |
| 87 | PM_WLED_LED3_SINK_MASK; |
| 88 | } |
| 89 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 90 | wled_reg_write(PM_WLED_CURRENT_SINK, value); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 91 | |
| 92 | dprintf(SPEW, "WLED Sink Success\n"); |
| 93 | |
| 94 | } |
| 95 | |
| 96 | void pm8x41_wled_iled_sync_control(uint8_t enable) { |
| 97 | |
| 98 | uint8_t value = 0x0; |
| 99 | |
| 100 | if (enable) { |
| 101 | value = PM_WLED_LED1_ILED_SYNC_MASK | |
Zhenhua Huang | d5355cb | 2013-09-04 16:03:01 +0800 | [diff] [blame] | 102 | PM_WLED_LED2_ILED_SYNC_MASK | |
| 103 | PM_WLED_LED3_ILED_SYNC_MASK; |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 106 | wled_reg_write(PM_WLED_ILED_SYNC_BIT, value); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 107 | |
| 108 | dprintf(SPEW, "WLED ILED Sync Success\n"); |
| 109 | |
| 110 | } |
| 111 | |
Jayant Shekhar | ae5280b | 2013-11-26 22:58:07 +0530 | [diff] [blame] | 112 | void pm8x41_wled_led_mod_enable(uint8_t enable) { |
| 113 | |
| 114 | uint8_t value = 0x0; |
| 115 | |
| 116 | if (enable) |
| 117 | value = PM_WLED_LED_MODULATOR_EN; |
| 118 | |
| 119 | wled_reg_write(PM_WLED_LED_CTNL_REG(1), value); |
| 120 | wled_reg_write(PM_WLED_LED_CTNL_REG(2), value); |
| 121 | wled_reg_write(PM_WLED_LED_CTNL_REG(3), value); |
| 122 | |
| 123 | dprintf(SPEW, "WLED LED Module Enable Success\n"); |
| 124 | |
| 125 | } |
| 126 | |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 127 | void pm8x41_wled_enable(uint8_t enable) { |
| 128 | |
| 129 | uint8_t value = 0x0; |
| 130 | |
| 131 | if (enable) |
| 132 | value = PM_WLED_ENABLE_MODULE_MASK; |
| 133 | |
Chandan Uddaraju | 58184aa | 2013-07-22 11:07:56 -0700 | [diff] [blame] | 134 | wled_reg_write(PM_WLED_ENABLE, value); |
Siddhartha Agrawal | 52d70b5 | 2013-01-18 20:49:41 -0800 | [diff] [blame] | 135 | |
| 136 | dprintf(SPEW, "WLED Enable Success\n"); |
| 137 | |
| 138 | } |