12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397 |
- /*
- * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
- *
- * Copyright 2007, 2008 Wolfson Microelectronics PLC.
- *
- * Author: Liam Girdwood
- * linux@wolfsonmicro.com
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- */
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/init.h>
- #include <linux/bitops.h>
- #include <linux/err.h>
- #include <linux/i2c.h>
- #include <linux/mfd/wm8350/core.h>
- #include <linux/mfd/wm8350/pmic.h>
- #include <linux/platform_device.h>
- #include <linux/regulator/driver.h>
- #include <linux/regulator/machine.h>
- /* Maximum value possible for VSEL */
- #define WM8350_DCDC_MAX_VSEL 0x66
- /* Microamps */
- static const int isink_cur[] = {
- 4,
- 5,
- 6,
- 7,
- 8,
- 10,
- 11,
- 14,
- 16,
- 19,
- 23,
- 27,
- 32,
- 39,
- 46,
- 54,
- 65,
- 77,
- 92,
- 109,
- 130,
- 154,
- 183,
- 218,
- 259,
- 308,
- 367,
- 436,
- 518,
- 616,
- 733,
- 872,
- 1037,
- 1233,
- 1466,
- 1744,
- 2073,
- 2466,
- 2933,
- 3487,
- 4147,
- 4932,
- 5865,
- 6975,
- 8294,
- 9864,
- 11730,
- 13949,
- 16589,
- 19728,
- 23460,
- 27899,
- 33178,
- 39455,
- 46920,
- 55798,
- 66355,
- 78910,
- 93840,
- 111596,
- 132710,
- 157820,
- 187681,
- 223191
- };
- static int get_isink_val(int min_uA, int max_uA, u16 *setting)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(isink_cur); i++) {
- if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
- *setting = i;
- return 0;
- }
- }
- return -EINVAL;
- }
- static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
- int max_uA)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int isink = rdev_get_id(rdev);
- u16 val, setting;
- int ret;
- ret = get_isink_val(min_uA, max_uA, &setting);
- if (ret != 0)
- return ret;
- switch (isink) {
- case WM8350_ISINK_A:
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
- ~WM8350_CS1_ISEL_MASK;
- wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A,
- val | setting);
- break;
- case WM8350_ISINK_B:
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
- ~WM8350_CS1_ISEL_MASK;
- wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B,
- val | setting);
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_isink_get_current(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int isink = rdev_get_id(rdev);
- u16 val;
- switch (isink) {
- case WM8350_ISINK_A:
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
- WM8350_CS1_ISEL_MASK;
- break;
- case WM8350_ISINK_B:
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
- WM8350_CS1_ISEL_MASK;
- break;
- default:
- return 0;
- }
- return isink_cur[val];
- }
- /* turn on ISINK followed by DCDC */
- static int wm8350_isink_enable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int isink = rdev_get_id(rdev);
- switch (isink) {
- case WM8350_ISINK_A:
- switch (wm8350->pmic.isink_A_dcdc) {
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
- WM8350_CS1_ENA);
- wm8350_set_bits(wm8350, WM8350_CSA_FLASH_CONTROL,
- WM8350_CS1_DRIVE);
- wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
- 1 << (wm8350->pmic.isink_A_dcdc -
- WM8350_DCDC_1));
- break;
- default:
- return -EINVAL;
- }
- break;
- case WM8350_ISINK_B:
- switch (wm8350->pmic.isink_B_dcdc) {
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
- WM8350_CS2_ENA);
- wm8350_set_bits(wm8350, WM8350_CSB_FLASH_CONTROL,
- WM8350_CS2_DRIVE);
- wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
- 1 << (wm8350->pmic.isink_B_dcdc -
- WM8350_DCDC_1));
- break;
- default:
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_isink_disable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int isink = rdev_get_id(rdev);
- switch (isink) {
- case WM8350_ISINK_A:
- switch (wm8350->pmic.isink_A_dcdc) {
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
- 1 << (wm8350->pmic.isink_A_dcdc -
- WM8350_DCDC_1));
- wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
- WM8350_CS1_ENA);
- break;
- default:
- return -EINVAL;
- }
- break;
- case WM8350_ISINK_B:
- switch (wm8350->pmic.isink_B_dcdc) {
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
- 1 << (wm8350->pmic.isink_B_dcdc -
- WM8350_DCDC_1));
- wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
- WM8350_CS2_ENA);
- break;
- default:
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_isink_is_enabled(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int isink = rdev_get_id(rdev);
- switch (isink) {
- case WM8350_ISINK_A:
- return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
- 0x8000;
- case WM8350_ISINK_B:
- return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
- 0x8000;
- }
- return -EINVAL;
- }
- static int wm8350_isink_enable_time(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int isink = rdev_get_id(rdev);
- int reg;
- switch (isink) {
- case WM8350_ISINK_A:
- reg = wm8350_reg_read(wm8350, WM8350_CSA_FLASH_CONTROL);
- break;
- case WM8350_ISINK_B:
- reg = wm8350_reg_read(wm8350, WM8350_CSB_FLASH_CONTROL);
- break;
- default:
- return -EINVAL;
- }
- if (reg & WM8350_CS1_FLASH_MODE) {
- switch (reg & WM8350_CS1_ON_RAMP_MASK) {
- case 0:
- return 0;
- case 1:
- return 1950;
- case 2:
- return 3910;
- case 3:
- return 7800;
- }
- } else {
- switch (reg & WM8350_CS1_ON_RAMP_MASK) {
- case 0:
- return 0;
- case 1:
- return 250000;
- case 2:
- return 500000;
- case 3:
- return 1000000;
- }
- }
- return -EINVAL;
- }
- int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
- u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp,
- u16 drive)
- {
- switch (isink) {
- case WM8350_ISINK_A:
- wm8350_reg_write(wm8350, WM8350_CSA_FLASH_CONTROL,
- (mode ? WM8350_CS1_FLASH_MODE : 0) |
- (trigger ? WM8350_CS1_TRIGSRC : 0) |
- duration | on_ramp | off_ramp | drive);
- break;
- case WM8350_ISINK_B:
- wm8350_reg_write(wm8350, WM8350_CSB_FLASH_CONTROL,
- (mode ? WM8350_CS2_FLASH_MODE : 0) |
- (trigger ? WM8350_CS2_TRIGSRC : 0) |
- duration | on_ramp | off_ramp | drive);
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
- static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int sel, volt_reg, dcdc = rdev_get_id(rdev);
- u16 val;
- dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, uV / 1000);
- switch (dcdc) {
- case WM8350_DCDC_1:
- volt_reg = WM8350_DCDC1_LOW_POWER;
- break;
- case WM8350_DCDC_3:
- volt_reg = WM8350_DCDC3_LOW_POWER;
- break;
- case WM8350_DCDC_4:
- volt_reg = WM8350_DCDC4_LOW_POWER;
- break;
- case WM8350_DCDC_6:
- volt_reg = WM8350_DCDC6_LOW_POWER;
- break;
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- default:
- return -EINVAL;
- }
- sel = regulator_map_voltage_linear(rdev, uV, uV);
- if (sel < 0)
- return sel;
- /* all DCDCs have same mV bits */
- val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
- wm8350_reg_write(wm8350, volt_reg, val | sel);
- return 0;
- }
- static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 val;
- switch (dcdc) {
- case WM8350_DCDC_1:
- val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER)
- & ~WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
- val | wm8350->pmic.dcdc1_hib_mode);
- break;
- case WM8350_DCDC_3:
- val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER)
- & ~WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
- val | wm8350->pmic.dcdc3_hib_mode);
- break;
- case WM8350_DCDC_4:
- val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER)
- & ~WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
- val | wm8350->pmic.dcdc4_hib_mode);
- break;
- case WM8350_DCDC_6:
- val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER)
- & ~WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
- val | wm8350->pmic.dcdc6_hib_mode);
- break;
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 val;
- switch (dcdc) {
- case WM8350_DCDC_1:
- val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
- wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
- val | WM8350_DCDC_HIB_MODE_DIS);
- break;
- case WM8350_DCDC_3:
- val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
- wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
- val | WM8350_DCDC_HIB_MODE_DIS);
- break;
- case WM8350_DCDC_4:
- val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
- wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
- val | WM8350_DCDC_HIB_MODE_DIS);
- break;
- case WM8350_DCDC_6:
- val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
- wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
- val | WM8350_DCDC_HIB_MODE_DIS);
- break;
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 val;
- switch (dcdc) {
- case WM8350_DCDC_2:
- val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
- & ~WM8350_DC2_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
- (WM8350_DC2_HIB_MODE_ACTIVE << WM8350_DC2_HIB_MODE_SHIFT));
- break;
- case WM8350_DCDC_5:
- val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
- & ~WM8350_DC5_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
- (WM8350_DC5_HIB_MODE_ACTIVE << WM8350_DC5_HIB_MODE_SHIFT));
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 val;
- switch (dcdc) {
- case WM8350_DCDC_2:
- val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
- & ~WM8350_DC2_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
- (WM8350_DC2_HIB_MODE_DISABLE << WM8350_DC2_HIB_MODE_SHIFT));
- break;
- case WM8350_DCDC_5:
- val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
- & ~WM8350_DC5_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
- (WM8350_DC5_HIB_MODE_DISABLE << WM8350_DC5_HIB_MODE_SHIFT));
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
- unsigned int mode)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 *hib_mode;
- switch (dcdc) {
- case WM8350_DCDC_1:
- hib_mode = &wm8350->pmic.dcdc1_hib_mode;
- break;
- case WM8350_DCDC_3:
- hib_mode = &wm8350->pmic.dcdc3_hib_mode;
- break;
- case WM8350_DCDC_4:
- hib_mode = &wm8350->pmic.dcdc4_hib_mode;
- break;
- case WM8350_DCDC_6:
- hib_mode = &wm8350->pmic.dcdc6_hib_mode;
- break;
- case WM8350_DCDC_2:
- case WM8350_DCDC_5:
- default:
- return -EINVAL;
- }
- switch (mode) {
- case REGULATOR_MODE_NORMAL:
- *hib_mode = WM8350_DCDC_HIB_MODE_IMAGE;
- break;
- case REGULATOR_MODE_IDLE:
- *hib_mode = WM8350_DCDC_HIB_MODE_STANDBY;
- break;
- case REGULATOR_MODE_STANDBY:
- *hib_mode = WM8350_DCDC_HIB_MODE_LDO_IM;
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static const struct regulator_linear_range wm8350_ldo_ranges[] = {
- REGULATOR_LINEAR_RANGE(900000, 0, 15, 50000),
- REGULATOR_LINEAR_RANGE(1800000, 16, 31, 100000),
- };
- static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int sel, volt_reg, ldo = rdev_get_id(rdev);
- u16 val;
- dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, uV / 1000);
- switch (ldo) {
- case WM8350_LDO_1:
- volt_reg = WM8350_LDO1_LOW_POWER;
- break;
- case WM8350_LDO_2:
- volt_reg = WM8350_LDO2_LOW_POWER;
- break;
- case WM8350_LDO_3:
- volt_reg = WM8350_LDO3_LOW_POWER;
- break;
- case WM8350_LDO_4:
- volt_reg = WM8350_LDO4_LOW_POWER;
- break;
- default:
- return -EINVAL;
- }
- sel = regulator_map_voltage_linear_range(rdev, uV, uV);
- if (sel < 0)
- return sel;
- /* all LDOs have same mV bits */
- val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
- wm8350_reg_write(wm8350, volt_reg, val | sel);
- return 0;
- }
- static int wm8350_ldo_set_suspend_enable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int volt_reg, ldo = rdev_get_id(rdev);
- u16 val;
- switch (ldo) {
- case WM8350_LDO_1:
- volt_reg = WM8350_LDO1_LOW_POWER;
- break;
- case WM8350_LDO_2:
- volt_reg = WM8350_LDO2_LOW_POWER;
- break;
- case WM8350_LDO_3:
- volt_reg = WM8350_LDO3_LOW_POWER;
- break;
- case WM8350_LDO_4:
- volt_reg = WM8350_LDO4_LOW_POWER;
- break;
- default:
- return -EINVAL;
- }
- /* all LDOs have same mV bits */
- val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, volt_reg, val);
- return 0;
- }
- static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int volt_reg, ldo = rdev_get_id(rdev);
- u16 val;
- switch (ldo) {
- case WM8350_LDO_1:
- volt_reg = WM8350_LDO1_LOW_POWER;
- break;
- case WM8350_LDO_2:
- volt_reg = WM8350_LDO2_LOW_POWER;
- break;
- case WM8350_LDO_3:
- volt_reg = WM8350_LDO3_LOW_POWER;
- break;
- case WM8350_LDO_4:
- volt_reg = WM8350_LDO4_LOW_POWER;
- break;
- default:
- return -EINVAL;
- }
- /* all LDOs have same mV bits */
- val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
- wm8350_reg_write(wm8350, volt_reg, val | WM8350_LDO1_HIB_MODE_DIS);
- return 0;
- }
- int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
- u16 stop, u16 fault)
- {
- int slot_reg;
- u16 val;
- dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
- __func__, dcdc, start, stop);
- /* slot valid ? */
- if (start > 15 || stop > 15)
- return -EINVAL;
- switch (dcdc) {
- case WM8350_DCDC_1:
- slot_reg = WM8350_DCDC1_TIMEOUTS;
- break;
- case WM8350_DCDC_2:
- slot_reg = WM8350_DCDC2_TIMEOUTS;
- break;
- case WM8350_DCDC_3:
- slot_reg = WM8350_DCDC3_TIMEOUTS;
- break;
- case WM8350_DCDC_4:
- slot_reg = WM8350_DCDC4_TIMEOUTS;
- break;
- case WM8350_DCDC_5:
- slot_reg = WM8350_DCDC5_TIMEOUTS;
- break;
- case WM8350_DCDC_6:
- slot_reg = WM8350_DCDC6_TIMEOUTS;
- break;
- default:
- return -EINVAL;
- }
- val = wm8350_reg_read(wm8350, slot_reg) &
- ~(WM8350_DC1_ENSLOT_MASK | WM8350_DC1_SDSLOT_MASK |
- WM8350_DC1_ERRACT_MASK);
- wm8350_reg_write(wm8350, slot_reg,
- val | (start << WM8350_DC1_ENSLOT_SHIFT) |
- (stop << WM8350_DC1_SDSLOT_SHIFT) |
- (fault << WM8350_DC1_ERRACT_SHIFT));
- return 0;
- }
- EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot);
- int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop)
- {
- int slot_reg;
- u16 val;
- dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
- __func__, ldo, start, stop);
- /* slot valid ? */
- if (start > 15 || stop > 15)
- return -EINVAL;
- switch (ldo) {
- case WM8350_LDO_1:
- slot_reg = WM8350_LDO1_TIMEOUTS;
- break;
- case WM8350_LDO_2:
- slot_reg = WM8350_LDO2_TIMEOUTS;
- break;
- case WM8350_LDO_3:
- slot_reg = WM8350_LDO3_TIMEOUTS;
- break;
- case WM8350_LDO_4:
- slot_reg = WM8350_LDO4_TIMEOUTS;
- break;
- default:
- return -EINVAL;
- }
- val = wm8350_reg_read(wm8350, slot_reg) & ~WM8350_LDO1_SDSLOT_MASK;
- wm8350_reg_write(wm8350, slot_reg, val | ((start << 10) | (stop << 6)));
- return 0;
- }
- EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot);
- int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode,
- u16 ilim, u16 ramp, u16 feedback)
- {
- u16 val;
- dev_dbg(wm8350->dev, "%s %d mode: %s %s\n", __func__, dcdc,
- mode ? "normal" : "boost", ilim ? "low" : "normal");
- switch (dcdc) {
- case WM8350_DCDC_2:
- val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
- & ~(WM8350_DC2_MODE_MASK | WM8350_DC2_ILIM_MASK |
- WM8350_DC2_RMP_MASK | WM8350_DC2_FBSRC_MASK);
- wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
- (mode << WM8350_DC2_MODE_SHIFT) |
- (ilim << WM8350_DC2_ILIM_SHIFT) |
- (ramp << WM8350_DC2_RMP_SHIFT) |
- (feedback << WM8350_DC2_FBSRC_SHIFT));
- break;
- case WM8350_DCDC_5:
- val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
- & ~(WM8350_DC5_MODE_MASK | WM8350_DC5_ILIM_MASK |
- WM8350_DC5_RMP_MASK | WM8350_DC5_FBSRC_MASK);
- wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
- (mode << WM8350_DC5_MODE_SHIFT) |
- (ilim << WM8350_DC5_ILIM_SHIFT) |
- (ramp << WM8350_DC5_RMP_SHIFT) |
- (feedback << WM8350_DC5_FBSRC_SHIFT));
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode);
- static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable)
- {
- int reg = 0, ret;
- switch (dcdc) {
- case WM8350_DCDC_1:
- reg = WM8350_DCDC1_FORCE_PWM;
- break;
- case WM8350_DCDC_3:
- reg = WM8350_DCDC3_FORCE_PWM;
- break;
- case WM8350_DCDC_4:
- reg = WM8350_DCDC4_FORCE_PWM;
- break;
- case WM8350_DCDC_6:
- reg = WM8350_DCDC6_FORCE_PWM;
- break;
- default:
- return -EINVAL;
- }
- if (enable)
- ret = wm8350_set_bits(wm8350, reg,
- WM8350_DCDC1_FORCE_PWM_ENA);
- else
- ret = wm8350_clear_bits(wm8350, reg,
- WM8350_DCDC1_FORCE_PWM_ENA);
- return ret;
- }
- static int wm8350_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 val;
- if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
- return -EINVAL;
- if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
- return -EINVAL;
- val = 1 << (dcdc - WM8350_DCDC_1);
- switch (mode) {
- case REGULATOR_MODE_FAST:
- /* force continuous mode */
- wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
- wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
- force_continuous_enable(wm8350, dcdc, 1);
- break;
- case REGULATOR_MODE_NORMAL:
- /* active / pulse skipping */
- wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
- wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
- force_continuous_enable(wm8350, dcdc, 0);
- break;
- case REGULATOR_MODE_IDLE:
- /* standby mode */
- force_continuous_enable(wm8350, dcdc, 0);
- wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
- wm8350_clear_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
- break;
- case REGULATOR_MODE_STANDBY:
- /* LDO mode */
- force_continuous_enable(wm8350, dcdc, 0);
- wm8350_set_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
- break;
- }
- return 0;
- }
- static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev)
- {
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- int dcdc = rdev_get_id(rdev);
- u16 mask, sleep, active, force;
- int mode = REGULATOR_MODE_NORMAL;
- int reg;
- switch (dcdc) {
- case WM8350_DCDC_1:
- reg = WM8350_DCDC1_FORCE_PWM;
- break;
- case WM8350_DCDC_3:
- reg = WM8350_DCDC3_FORCE_PWM;
- break;
- case WM8350_DCDC_4:
- reg = WM8350_DCDC4_FORCE_PWM;
- break;
- case WM8350_DCDC_6:
- reg = WM8350_DCDC6_FORCE_PWM;
- break;
- default:
- return -EINVAL;
- }
- mask = 1 << (dcdc - WM8350_DCDC_1);
- active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask;
- force = wm8350_reg_read(wm8350, reg) & WM8350_DCDC1_FORCE_PWM_ENA;
- sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask;
- dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x",
- mask, active, sleep, force);
- if (active && !sleep) {
- if (force)
- mode = REGULATOR_MODE_FAST;
- else
- mode = REGULATOR_MODE_NORMAL;
- } else if (!active && !sleep)
- mode = REGULATOR_MODE_IDLE;
- else if (sleep)
- mode = REGULATOR_MODE_STANDBY;
- return mode;
- }
- static unsigned int wm8350_ldo_get_mode(struct regulator_dev *rdev)
- {
- return REGULATOR_MODE_NORMAL;
- }
- struct wm8350_dcdc_efficiency {
- int uA_load_min;
- int uA_load_max;
- unsigned int mode;
- };
- static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency[] = {
- {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */
- {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */
- {100000, 1000000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
- {-1, -1, REGULATOR_MODE_NORMAL},
- };
- static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency[] = {
- {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */
- {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */
- {100000, 800000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
- {-1, -1, REGULATOR_MODE_NORMAL},
- };
- static unsigned int get_mode(int uA, const struct wm8350_dcdc_efficiency *eff)
- {
- int i = 0;
- while (eff[i].uA_load_min != -1) {
- if (uA >= eff[i].uA_load_min && uA <= eff[i].uA_load_max)
- return eff[i].mode;
- }
- return REGULATOR_MODE_NORMAL;
- }
- /* Query the regulator for it's most efficient mode @ uV,uA
- * WM8350 regulator efficiency is pretty similar over
- * different input and output uV.
- */
- static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev,
- int input_uV, int output_uV,
- int output_uA)
- {
- int dcdc = rdev_get_id(rdev), mode;
- switch (dcdc) {
- case WM8350_DCDC_1:
- case WM8350_DCDC_6:
- mode = get_mode(output_uA, dcdc1_6_efficiency);
- break;
- case WM8350_DCDC_3:
- case WM8350_DCDC_4:
- mode = get_mode(output_uA, dcdc3_4_efficiency);
- break;
- default:
- mode = REGULATOR_MODE_NORMAL;
- break;
- }
- return mode;
- }
- static const struct regulator_ops wm8350_dcdc_ops = {
- .set_voltage_sel = regulator_set_voltage_sel_regmap,
- .get_voltage_sel = regulator_get_voltage_sel_regmap,
- .list_voltage = regulator_list_voltage_linear,
- .map_voltage = regulator_map_voltage_linear,
- .enable = regulator_enable_regmap,
- .disable = regulator_disable_regmap,
- .is_enabled = regulator_is_enabled_regmap,
- .get_mode = wm8350_dcdc_get_mode,
- .set_mode = wm8350_dcdc_set_mode,
- .get_optimum_mode = wm8350_dcdc_get_optimum_mode,
- .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage,
- .set_suspend_enable = wm8350_dcdc_set_suspend_enable,
- .set_suspend_disable = wm8350_dcdc_set_suspend_disable,
- .set_suspend_mode = wm8350_dcdc_set_suspend_mode,
- };
- static const struct regulator_ops wm8350_dcdc2_5_ops = {
- .enable = regulator_enable_regmap,
- .disable = regulator_disable_regmap,
- .is_enabled = regulator_is_enabled_regmap,
- .set_suspend_enable = wm8350_dcdc25_set_suspend_enable,
- .set_suspend_disable = wm8350_dcdc25_set_suspend_disable,
- };
- static const struct regulator_ops wm8350_ldo_ops = {
- .map_voltage = regulator_map_voltage_linear_range,
- .set_voltage_sel = regulator_set_voltage_sel_regmap,
- .get_voltage_sel = regulator_get_voltage_sel_regmap,
- .list_voltage = regulator_list_voltage_linear_range,
- .enable = regulator_enable_regmap,
- .disable = regulator_disable_regmap,
- .is_enabled = regulator_is_enabled_regmap,
- .get_mode = wm8350_ldo_get_mode,
- .set_suspend_voltage = wm8350_ldo_set_suspend_voltage,
- .set_suspend_enable = wm8350_ldo_set_suspend_enable,
- .set_suspend_disable = wm8350_ldo_set_suspend_disable,
- };
- static const struct regulator_ops wm8350_isink_ops = {
- .set_current_limit = wm8350_isink_set_current,
- .get_current_limit = wm8350_isink_get_current,
- .enable = wm8350_isink_enable,
- .disable = wm8350_isink_disable,
- .is_enabled = wm8350_isink_is_enabled,
- .enable_time = wm8350_isink_enable_time,
- };
- static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
- {
- .name = "DCDC1",
- .id = WM8350_DCDC_1,
- .ops = &wm8350_dcdc_ops,
- .irq = WM8350_IRQ_UV_DC1,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
- .min_uV = 850000,
- .uV_step = 25000,
- .vsel_reg = WM8350_DCDC1_CONTROL,
- .vsel_mask = WM8350_DC1_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_DC1_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "DCDC2",
- .id = WM8350_DCDC_2,
- .ops = &wm8350_dcdc2_5_ops,
- .irq = WM8350_IRQ_UV_DC2,
- .type = REGULATOR_VOLTAGE,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_DC2_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "DCDC3",
- .id = WM8350_DCDC_3,
- .ops = &wm8350_dcdc_ops,
- .irq = WM8350_IRQ_UV_DC3,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
- .min_uV = 850000,
- .uV_step = 25000,
- .vsel_reg = WM8350_DCDC3_CONTROL,
- .vsel_mask = WM8350_DC3_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_DC3_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "DCDC4",
- .id = WM8350_DCDC_4,
- .ops = &wm8350_dcdc_ops,
- .irq = WM8350_IRQ_UV_DC4,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
- .min_uV = 850000,
- .uV_step = 25000,
- .vsel_reg = WM8350_DCDC4_CONTROL,
- .vsel_mask = WM8350_DC4_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_DC4_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "DCDC5",
- .id = WM8350_DCDC_5,
- .ops = &wm8350_dcdc2_5_ops,
- .irq = WM8350_IRQ_UV_DC5,
- .type = REGULATOR_VOLTAGE,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_DC5_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "DCDC6",
- .id = WM8350_DCDC_6,
- .ops = &wm8350_dcdc_ops,
- .irq = WM8350_IRQ_UV_DC6,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
- .min_uV = 850000,
- .uV_step = 25000,
- .vsel_reg = WM8350_DCDC6_CONTROL,
- .vsel_mask = WM8350_DC6_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_DC6_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "LDO1",
- .id = WM8350_LDO_1,
- .ops = &wm8350_ldo_ops,
- .irq = WM8350_IRQ_UV_LDO1,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_LDO1_VSEL_MASK + 1,
- .linear_ranges = wm8350_ldo_ranges,
- .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
- .vsel_reg = WM8350_LDO1_CONTROL,
- .vsel_mask = WM8350_LDO1_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_LDO1_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "LDO2",
- .id = WM8350_LDO_2,
- .ops = &wm8350_ldo_ops,
- .irq = WM8350_IRQ_UV_LDO2,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_LDO2_VSEL_MASK + 1,
- .linear_ranges = wm8350_ldo_ranges,
- .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
- .vsel_reg = WM8350_LDO2_CONTROL,
- .vsel_mask = WM8350_LDO2_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_LDO2_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "LDO3",
- .id = WM8350_LDO_3,
- .ops = &wm8350_ldo_ops,
- .irq = WM8350_IRQ_UV_LDO3,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_LDO3_VSEL_MASK + 1,
- .linear_ranges = wm8350_ldo_ranges,
- .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
- .vsel_reg = WM8350_LDO3_CONTROL,
- .vsel_mask = WM8350_LDO3_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_LDO3_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "LDO4",
- .id = WM8350_LDO_4,
- .ops = &wm8350_ldo_ops,
- .irq = WM8350_IRQ_UV_LDO4,
- .type = REGULATOR_VOLTAGE,
- .n_voltages = WM8350_LDO4_VSEL_MASK + 1,
- .linear_ranges = wm8350_ldo_ranges,
- .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
- .vsel_reg = WM8350_LDO4_CONTROL,
- .vsel_mask = WM8350_LDO4_VSEL_MASK,
- .enable_reg = WM8350_DCDC_LDO_REQUESTED,
- .enable_mask = WM8350_LDO4_ENA,
- .owner = THIS_MODULE,
- },
- {
- .name = "ISINKA",
- .id = WM8350_ISINK_A,
- .ops = &wm8350_isink_ops,
- .irq = WM8350_IRQ_CS1,
- .type = REGULATOR_CURRENT,
- .owner = THIS_MODULE,
- },
- {
- .name = "ISINKB",
- .id = WM8350_ISINK_B,
- .ops = &wm8350_isink_ops,
- .irq = WM8350_IRQ_CS2,
- .type = REGULATOR_CURRENT,
- .owner = THIS_MODULE,
- },
- };
- static irqreturn_t pmic_uv_handler(int irq, void *data)
- {
- struct regulator_dev *rdev = (struct regulator_dev *)data;
- mutex_lock(&rdev->mutex);
- if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2)
- regulator_notifier_call_chain(rdev,
- REGULATOR_EVENT_REGULATION_OUT,
- NULL);
- else
- regulator_notifier_call_chain(rdev,
- REGULATOR_EVENT_UNDER_VOLTAGE,
- NULL);
- mutex_unlock(&rdev->mutex);
- return IRQ_HANDLED;
- }
- static int wm8350_regulator_probe(struct platform_device *pdev)
- {
- struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
- struct regulator_config config = { };
- struct regulator_dev *rdev;
- int ret;
- u16 val;
- if (pdev->id < WM8350_DCDC_1 || pdev->id > WM8350_ISINK_B)
- return -ENODEV;
- /* do any regulatior specific init */
- switch (pdev->id) {
- case WM8350_DCDC_1:
- val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
- wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- break;
- case WM8350_DCDC_3:
- val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
- wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- break;
- case WM8350_DCDC_4:
- val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
- wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- break;
- case WM8350_DCDC_6:
- val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
- wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
- break;
- }
- config.dev = &pdev->dev;
- config.init_data = dev_get_platdata(&pdev->dev);
- config.driver_data = dev_get_drvdata(&pdev->dev);
- config.regmap = wm8350->regmap;
- /* register regulator */
- rdev = devm_regulator_register(&pdev->dev, &wm8350_reg[pdev->id],
- &config);
- if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "failed to register %s\n",
- wm8350_reg[pdev->id].name);
- return PTR_ERR(rdev);
- }
- /* register regulator IRQ */
- ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
- pmic_uv_handler, 0, "UV", rdev);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
- wm8350_reg[pdev->id].name);
- return ret;
- }
- return 0;
- }
- static int wm8350_regulator_remove(struct platform_device *pdev)
- {
- struct regulator_dev *rdev = platform_get_drvdata(pdev);
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
- wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev);
- return 0;
- }
- int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
- struct regulator_init_data *initdata)
- {
- struct platform_device *pdev;
- int ret;
- if (reg < 0 || reg >= NUM_WM8350_REGULATORS)
- return -EINVAL;
- if (wm8350->pmic.pdev[reg])
- return -EBUSY;
- if (reg >= WM8350_DCDC_1 && reg <= WM8350_DCDC_6 &&
- reg > wm8350->pmic.max_dcdc)
- return -ENODEV;
- if (reg >= WM8350_ISINK_A && reg <= WM8350_ISINK_B &&
- reg > wm8350->pmic.max_isink)
- return -ENODEV;
- pdev = platform_device_alloc("wm8350-regulator", reg);
- if (!pdev)
- return -ENOMEM;
- wm8350->pmic.pdev[reg] = pdev;
- initdata->driver_data = wm8350;
- pdev->dev.platform_data = initdata;
- pdev->dev.parent = wm8350->dev;
- platform_set_drvdata(pdev, wm8350);
- ret = platform_device_add(pdev);
- if (ret != 0) {
- dev_err(wm8350->dev, "Failed to register regulator %d: %d\n",
- reg, ret);
- platform_device_put(pdev);
- wm8350->pmic.pdev[reg] = NULL;
- }
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm8350_register_regulator);
- /**
- * wm8350_register_led - Register a WM8350 LED output
- *
- * @param wm8350 The WM8350 device to configure.
- * @param lednum LED device index to create.
- * @param dcdc The DCDC to use for the LED.
- * @param isink The ISINK to use for the LED.
- * @param pdata Configuration for the LED.
- *
- * The WM8350 supports the use of an ISINK together with a DCDC to
- * provide a power-efficient LED driver. This function registers the
- * regulators and instantiates the platform device for a LED. The
- * operating modes for the LED regulators must be configured using
- * wm8350_isink_set_flash(), wm8350_dcdc25_set_mode() and
- * wm8350_dcdc_set_slot() prior to calling this function.
- */
- int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink,
- struct wm8350_led_platform_data *pdata)
- {
- struct wm8350_led *led;
- struct platform_device *pdev;
- int ret;
- if (lednum >= ARRAY_SIZE(wm8350->pmic.led) || lednum < 0) {
- dev_err(wm8350->dev, "Invalid LED index %d\n", lednum);
- return -ENODEV;
- }
- led = &wm8350->pmic.led[lednum];
- if (led->pdev) {
- dev_err(wm8350->dev, "LED %d already allocated\n", lednum);
- return -EINVAL;
- }
- pdev = platform_device_alloc("wm8350-led", lednum);
- if (pdev == NULL) {
- dev_err(wm8350->dev, "Failed to allocate LED %d\n", lednum);
- return -ENOMEM;
- }
- led->isink_consumer.dev_name = dev_name(&pdev->dev);
- led->isink_consumer.supply = "led_isink";
- led->isink_init.num_consumer_supplies = 1;
- led->isink_init.consumer_supplies = &led->isink_consumer;
- led->isink_init.constraints.min_uA = 0;
- led->isink_init.constraints.max_uA = pdata->max_uA;
- led->isink_init.constraints.valid_ops_mask
- = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS;
- led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
- ret = wm8350_register_regulator(wm8350, isink, &led->isink_init);
- if (ret != 0) {
- platform_device_put(pdev);
- return ret;
- }
- led->dcdc_consumer.dev_name = dev_name(&pdev->dev);
- led->dcdc_consumer.supply = "led_vcc";
- led->dcdc_init.num_consumer_supplies = 1;
- led->dcdc_init.consumer_supplies = &led->dcdc_consumer;
- led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
- led->dcdc_init.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
- ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init);
- if (ret != 0) {
- platform_device_put(pdev);
- return ret;
- }
- switch (isink) {
- case WM8350_ISINK_A:
- wm8350->pmic.isink_A_dcdc = dcdc;
- break;
- case WM8350_ISINK_B:
- wm8350->pmic.isink_B_dcdc = dcdc;
- break;
- }
- pdev->dev.platform_data = pdata;
- pdev->dev.parent = wm8350->dev;
- ret = platform_device_add(pdev);
- if (ret != 0) {
- dev_err(wm8350->dev, "Failed to register LED %d: %d\n",
- lednum, ret);
- platform_device_put(pdev);
- return ret;
- }
- led->pdev = pdev;
- return 0;
- }
- EXPORT_SYMBOL_GPL(wm8350_register_led);
- static struct platform_driver wm8350_regulator_driver = {
- .probe = wm8350_regulator_probe,
- .remove = wm8350_regulator_remove,
- .driver = {
- .name = "wm8350-regulator",
- },
- };
- static int __init wm8350_regulator_init(void)
- {
- return platform_driver_register(&wm8350_regulator_driver);
- }
- subsys_initcall(wm8350_regulator_init);
- static void __exit wm8350_regulator_exit(void)
- {
- platform_driver_unregister(&wm8350_regulator_driver);
- }
- module_exit(wm8350_regulator_exit);
- /* Module information */
- MODULE_AUTHOR("Liam Girdwood");
- MODULE_DESCRIPTION("WM8350 voltage and current regulator driver");
- MODULE_LICENSE("GPL");
- MODULE_ALIAS("platform:wm8350-regulator");
|