| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC |
|---|
| 3 | | - * |
|---|
| 4 | | - * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
|---|
| 5 | | - * |
|---|
| 6 | | - * Author: Liam Girdwood |
|---|
| 7 | | - * linux@wolfsonmicro.com |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 10 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 11 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 12 | | - * option) any later version. |
|---|
| 13 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 2 | +// |
|---|
| 3 | +// wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC |
|---|
| 4 | +// |
|---|
| 5 | +// Copyright 2007, 2008 Wolfson Microelectronics PLC. |
|---|
| 6 | +// |
|---|
| 7 | +// Author: Liam Girdwood |
|---|
| 8 | +// linux@wolfsonmicro.com |
|---|
| 14 | 9 | |
|---|
| 15 | 10 | #include <linux/module.h> |
|---|
| 16 | 11 | #include <linux/moduleparam.h> |
|---|
| .. | .. |
|---|
| 28 | 23 | #define WM8350_DCDC_MAX_VSEL 0x66 |
|---|
| 29 | 24 | |
|---|
| 30 | 25 | /* Microamps */ |
|---|
| 31 | | -static const int isink_cur[] = { |
|---|
| 26 | +static const unsigned int isink_cur[] = { |
|---|
| 32 | 27 | 4, |
|---|
| 33 | 28 | 5, |
|---|
| 34 | 29 | 6, |
|---|
| .. | .. |
|---|
| 94 | 89 | 187681, |
|---|
| 95 | 90 | 223191 |
|---|
| 96 | 91 | }; |
|---|
| 97 | | - |
|---|
| 98 | | -static int get_isink_val(int min_uA, int max_uA, u16 *setting) |
|---|
| 99 | | -{ |
|---|
| 100 | | - int i; |
|---|
| 101 | | - |
|---|
| 102 | | - for (i = 0; i < ARRAY_SIZE(isink_cur); i++) { |
|---|
| 103 | | - if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) { |
|---|
| 104 | | - *setting = i; |
|---|
| 105 | | - return 0; |
|---|
| 106 | | - } |
|---|
| 107 | | - } |
|---|
| 108 | | - return -EINVAL; |
|---|
| 109 | | -} |
|---|
| 110 | | - |
|---|
| 111 | | -static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, |
|---|
| 112 | | - int max_uA) |
|---|
| 113 | | -{ |
|---|
| 114 | | - struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
|---|
| 115 | | - int isink = rdev_get_id(rdev); |
|---|
| 116 | | - u16 val, setting; |
|---|
| 117 | | - int ret; |
|---|
| 118 | | - |
|---|
| 119 | | - ret = get_isink_val(min_uA, max_uA, &setting); |
|---|
| 120 | | - if (ret != 0) |
|---|
| 121 | | - return ret; |
|---|
| 122 | | - |
|---|
| 123 | | - switch (isink) { |
|---|
| 124 | | - case WM8350_ISINK_A: |
|---|
| 125 | | - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & |
|---|
| 126 | | - ~WM8350_CS1_ISEL_MASK; |
|---|
| 127 | | - wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A, |
|---|
| 128 | | - val | setting); |
|---|
| 129 | | - break; |
|---|
| 130 | | - case WM8350_ISINK_B: |
|---|
| 131 | | - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & |
|---|
| 132 | | - ~WM8350_CS1_ISEL_MASK; |
|---|
| 133 | | - wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B, |
|---|
| 134 | | - val | setting); |
|---|
| 135 | | - break; |
|---|
| 136 | | - default: |
|---|
| 137 | | - return -EINVAL; |
|---|
| 138 | | - } |
|---|
| 139 | | - |
|---|
| 140 | | - return 0; |
|---|
| 141 | | -} |
|---|
| 142 | | - |
|---|
| 143 | | -static int wm8350_isink_get_current(struct regulator_dev *rdev) |
|---|
| 144 | | -{ |
|---|
| 145 | | - struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
|---|
| 146 | | - int isink = rdev_get_id(rdev); |
|---|
| 147 | | - u16 val; |
|---|
| 148 | | - |
|---|
| 149 | | - switch (isink) { |
|---|
| 150 | | - case WM8350_ISINK_A: |
|---|
| 151 | | - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & |
|---|
| 152 | | - WM8350_CS1_ISEL_MASK; |
|---|
| 153 | | - break; |
|---|
| 154 | | - case WM8350_ISINK_B: |
|---|
| 155 | | - val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & |
|---|
| 156 | | - WM8350_CS1_ISEL_MASK; |
|---|
| 157 | | - break; |
|---|
| 158 | | - default: |
|---|
| 159 | | - return 0; |
|---|
| 160 | | - } |
|---|
| 161 | | - |
|---|
| 162 | | - return isink_cur[val]; |
|---|
| 163 | | -} |
|---|
| 164 | 92 | |
|---|
| 165 | 93 | /* turn on ISINK followed by DCDC */ |
|---|
| 166 | 94 | static int wm8350_isink_enable(struct regulator_dev *rdev) |
|---|
| .. | .. |
|---|
| 542 | 470 | return 0; |
|---|
| 543 | 471 | } |
|---|
| 544 | 472 | |
|---|
| 545 | | -static const struct regulator_linear_range wm8350_ldo_ranges[] = { |
|---|
| 473 | +static const struct linear_range wm8350_ldo_ranges[] = { |
|---|
| 546 | 474 | REGULATOR_LINEAR_RANGE(900000, 0, 15, 50000), |
|---|
| 547 | 475 | REGULATOR_LINEAR_RANGE(1800000, 16, 31, 100000), |
|---|
| 548 | 476 | }; |
|---|
| .. | .. |
|---|
| 982 | 910 | }; |
|---|
| 983 | 911 | |
|---|
| 984 | 912 | static const struct regulator_ops wm8350_isink_ops = { |
|---|
| 985 | | - .set_current_limit = wm8350_isink_set_current, |
|---|
| 986 | | - .get_current_limit = wm8350_isink_get_current, |
|---|
| 913 | + .set_current_limit = regulator_set_current_limit_regmap, |
|---|
| 914 | + .get_current_limit = regulator_get_current_limit_regmap, |
|---|
| 987 | 915 | .enable = wm8350_isink_enable, |
|---|
| 988 | 916 | .disable = wm8350_isink_disable, |
|---|
| 989 | 917 | .is_enabled = wm8350_isink_is_enabled, |
|---|
| .. | .. |
|---|
| 1138 | 1066 | .irq = WM8350_IRQ_CS1, |
|---|
| 1139 | 1067 | .type = REGULATOR_CURRENT, |
|---|
| 1140 | 1068 | .owner = THIS_MODULE, |
|---|
| 1069 | + .curr_table = isink_cur, |
|---|
| 1070 | + .n_current_limits = ARRAY_SIZE(isink_cur), |
|---|
| 1071 | + .csel_reg = WM8350_CURRENT_SINK_DRIVER_A, |
|---|
| 1072 | + .csel_mask = WM8350_CS1_ISEL_MASK, |
|---|
| 1141 | 1073 | }, |
|---|
| 1142 | 1074 | { |
|---|
| 1143 | 1075 | .name = "ISINKB", |
|---|
| .. | .. |
|---|
| 1146 | 1078 | .irq = WM8350_IRQ_CS2, |
|---|
| 1147 | 1079 | .type = REGULATOR_CURRENT, |
|---|
| 1148 | 1080 | .owner = THIS_MODULE, |
|---|
| 1081 | + .curr_table = isink_cur, |
|---|
| 1082 | + .n_current_limits = ARRAY_SIZE(isink_cur), |
|---|
| 1083 | + .csel_reg = WM8350_CURRENT_SINK_DRIVER_B, |
|---|
| 1084 | + .csel_mask = WM8350_CS2_ISEL_MASK, |
|---|
| 1149 | 1085 | }, |
|---|
| 1150 | 1086 | }; |
|---|
| 1151 | 1087 | |
|---|
| .. | .. |
|---|
| 1153 | 1089 | { |
|---|
| 1154 | 1090 | struct regulator_dev *rdev = (struct regulator_dev *)data; |
|---|
| 1155 | 1091 | |
|---|
| 1156 | | - mutex_lock(&rdev->mutex); |
|---|
| 1157 | 1092 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) |
|---|
| 1158 | 1093 | regulator_notifier_call_chain(rdev, |
|---|
| 1159 | 1094 | REGULATOR_EVENT_REGULATION_OUT, |
|---|
| .. | .. |
|---|
| 1162 | 1097 | regulator_notifier_call_chain(rdev, |
|---|
| 1163 | 1098 | REGULATOR_EVENT_UNDER_VOLTAGE, |
|---|
| 1164 | 1099 | NULL); |
|---|
| 1165 | | - mutex_unlock(&rdev->mutex); |
|---|
| 1166 | 1100 | |
|---|
| 1167 | 1101 | return IRQ_HANDLED; |
|---|
| 1168 | 1102 | } |
|---|
| .. | .. |
|---|
| 1280 | 1214 | /** |
|---|
| 1281 | 1215 | * wm8350_register_led - Register a WM8350 LED output |
|---|
| 1282 | 1216 | * |
|---|
| 1283 | | - * @param wm8350 The WM8350 device to configure. |
|---|
| 1284 | | - * @param lednum LED device index to create. |
|---|
| 1285 | | - * @param dcdc The DCDC to use for the LED. |
|---|
| 1286 | | - * @param isink The ISINK to use for the LED. |
|---|
| 1287 | | - * @param pdata Configuration for the LED. |
|---|
| 1217 | + * @wm8350: The WM8350 device to configure. |
|---|
| 1218 | + * @lednum: LED device index to create. |
|---|
| 1219 | + * @dcdc: The DCDC to use for the LED. |
|---|
| 1220 | + * @isink: The ISINK to use for the LED. |
|---|
| 1221 | + * @pdata: Configuration for the LED. |
|---|
| 1288 | 1222 | * |
|---|
| 1289 | 1223 | * The WM8350 supports the use of an ISINK together with a DCDC to |
|---|
| 1290 | 1224 | * provide a power-efficient LED driver. This function registers the |
|---|