1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699 |
- /*
- * wm831x-core.c -- Device access for Wolfson WM831x PMICs
- *
- * Copyright 2009 Wolfson Microelectronics PLC.
- *
- * Author: Mark Brown <broonie@opensource.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/kernel.h>
- #include <linux/module.h>
- #include <linux/i2c.h>
- #include <linux/bcd.h>
- #include <linux/delay.h>
- #include <linux/mfd/core.h>
- #include <linux/mfd/wm831x/core.h>
- #include <linux/mfd/wm831x/pdata.h>
- #include <linux/mfd/wm831x/irq.h>
- #include <linux/mfd/wm831x/auxadc.h>
- #include <linux/mfd/wm831x/otp.h>
- #include <linux/mfd/wm831x/regulator.h>
- /* Current settings - values are 2*2^(reg_val/4) microamps. These are
- * exported since they are used by multiple drivers.
- */
- int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
- 2,
- 2,
- 3,
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 10,
- 11,
- 13,
- 16,
- 19,
- 23,
- 27,
- 32,
- 38,
- 45,
- 54,
- 64,
- 76,
- 91,
- 108,
- 128,
- 152,
- 181,
- 215,
- 256,
- 304,
- 362,
- 431,
- 512,
- 609,
- 724,
- 861,
- 1024,
- 1218,
- 1448,
- 1722,
- 2048,
- 2435,
- 2896,
- 3444,
- 4096,
- 4871,
- 5793,
- 6889,
- 8192,
- 9742,
- 11585,
- 13777,
- 16384,
- 19484,
- 23170,
- 27554,
- };
- EXPORT_SYMBOL_GPL(wm831x_isinkv_values);
- enum wm831x_parent {
- WM8310 = 0x8310,
- WM8311 = 0x8311,
- WM8312 = 0x8312,
- WM8320 = 0x8320,
- };
- static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
- {
- if (!wm831x->locked)
- return 0;
- switch (reg) {
- case WM831X_WATCHDOG:
- case WM831X_DC4_CONTROL:
- case WM831X_ON_PIN_CONTROL:
- case WM831X_BACKUP_CHARGER_CONTROL:
- case WM831X_CHARGER_CONTROL_1:
- case WM831X_CHARGER_CONTROL_2:
- return 1;
- default:
- return 0;
- }
- }
- /**
- * wm831x_reg_unlock: Unlock user keyed registers
- *
- * The WM831x has a user key preventing writes to particularly
- * critical registers. This function locks those registers,
- * allowing writes to them.
- */
- void wm831x_reg_lock(struct wm831x *wm831x)
- {
- int ret;
- ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
- if (ret == 0) {
- dev_vdbg(wm831x->dev, "Registers locked\n");
- mutex_lock(&wm831x->io_lock);
- WARN_ON(wm831x->locked);
- wm831x->locked = 1;
- mutex_unlock(&wm831x->io_lock);
- } else {
- dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
- }
- }
- EXPORT_SYMBOL_GPL(wm831x_reg_lock);
- /**
- * wm831x_reg_unlock: Unlock user keyed registers
- *
- * The WM831x has a user key preventing writes to particularly
- * critical registers. This function locks those registers,
- * preventing spurious writes.
- */
- int wm831x_reg_unlock(struct wm831x *wm831x)
- {
- int ret;
- /* 0x9716 is the value required to unlock the registers */
- ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
- if (ret == 0) {
- dev_vdbg(wm831x->dev, "Registers unlocked\n");
- mutex_lock(&wm831x->io_lock);
- WARN_ON(!wm831x->locked);
- wm831x->locked = 0;
- mutex_unlock(&wm831x->io_lock);
- }
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
- static int wm831x_read(struct wm831x *wm831x, unsigned short reg,
- int bytes, void *dest)
- {
- int ret, i;
- u16 *buf = dest;
- BUG_ON(bytes % 2);
- BUG_ON(bytes <= 0);
- ret = wm831x->read_dev(wm831x, reg, bytes, dest);
- if (ret < 0)
- return ret;
- for (i = 0; i < bytes / 2; i++) {
- buf[i] = be16_to_cpu(buf[i]);
- dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n",
- buf[i], reg + i, reg + i);
- }
- return 0;
- }
- /**
- * wm831x_reg_read: Read a single WM831x register.
- *
- * @wm831x: Device to read from.
- * @reg: Register to read.
- */
- int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
- {
- unsigned short val;
- int ret;
- mutex_lock(&wm831x->io_lock);
- ret = wm831x_read(wm831x, reg, 2, &val);
- mutex_unlock(&wm831x->io_lock);
- if (ret < 0)
- return ret;
- else
- return val;
- }
- EXPORT_SYMBOL_GPL(wm831x_reg_read);
- /**
- * wm831x_bulk_read: Read multiple WM831x registers
- *
- * @wm831x: Device to read from
- * @reg: First register
- * @count: Number of registers
- * @buf: Buffer to fill.
- */
- int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
- int count, u16 *buf)
- {
- int ret;
- mutex_lock(&wm831x->io_lock);
- ret = wm831x_read(wm831x, reg, count * 2, buf);
- mutex_unlock(&wm831x->io_lock);
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm831x_bulk_read);
- static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
- int bytes, void *src)
- {
- u16 *buf = src;
- int i;
- BUG_ON(bytes % 2);
- BUG_ON(bytes <= 0);
- for (i = 0; i < bytes / 2; i++) {
- if (wm831x_reg_locked(wm831x, reg))
- return -EPERM;
- dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
- buf[i], reg + i, reg + i);
- buf[i] = cpu_to_be16(buf[i]);
- }
- return wm831x->write_dev(wm831x, reg, bytes, src);
- }
- /**
- * wm831x_reg_write: Write a single WM831x register.
- *
- * @wm831x: Device to write to.
- * @reg: Register to write to.
- * @val: Value to write.
- */
- int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
- unsigned short val)
- {
- int ret;
- mutex_lock(&wm831x->io_lock);
- ret = wm831x_write(wm831x, reg, 2, &val);
- mutex_unlock(&wm831x->io_lock);
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm831x_reg_write);
- /**
- * wm831x_set_bits: Set the value of a bitfield in a WM831x register
- *
- * @wm831x: Device to write to.
- * @reg: Register to write to.
- * @mask: Mask of bits to set.
- * @val: Value to set (unshifted)
- */
- int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
- unsigned short mask, unsigned short val)
- {
- int ret;
- u16 r;
- mutex_lock(&wm831x->io_lock);
- ret = wm831x_read(wm831x, reg, 2, &r);
- if (ret < 0)
- goto out;
- r &= ~mask;
- r |= val;
- ret = wm831x_write(wm831x, reg, 2, &r);
- out:
- mutex_unlock(&wm831x->io_lock);
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm831x_set_bits);
- /**
- * wm831x_auxadc_read: Read a value from the WM831x AUXADC
- *
- * @wm831x: Device to read from.
- * @input: AUXADC input to read.
- */
- int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
- {
- int tries = 10;
- int ret, src;
- mutex_lock(&wm831x->auxadc_lock);
- ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
- WM831X_AUX_ENA, WM831X_AUX_ENA);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to enable AUXADC: %d\n", ret);
- goto out;
- }
- /* We force a single source at present */
- src = input;
- ret = wm831x_reg_write(wm831x, WM831X_AUXADC_SOURCE,
- 1 << src);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to set AUXADC source: %d\n", ret);
- goto out;
- }
- ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
- WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to start AUXADC: %d\n", ret);
- goto disable;
- }
- do {
- msleep(1);
- ret = wm831x_reg_read(wm831x, WM831X_AUXADC_CONTROL);
- if (ret < 0)
- ret = WM831X_AUX_CVT_ENA;
- } while ((ret & WM831X_AUX_CVT_ENA) && --tries);
- if (ret & WM831X_AUX_CVT_ENA) {
- dev_err(wm831x->dev, "Timed out reading AUXADC\n");
- ret = -EBUSY;
- goto disable;
- }
- ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to read AUXADC data: %d\n", ret);
- } else {
- src = ((ret & WM831X_AUX_DATA_SRC_MASK)
- >> WM831X_AUX_DATA_SRC_SHIFT) - 1;
- if (src == 14)
- src = WM831X_AUX_CAL;
- if (src != input) {
- dev_err(wm831x->dev, "Data from source %d not %d\n",
- src, input);
- ret = -EINVAL;
- } else {
- ret &= WM831X_AUX_DATA_MASK;
- }
- }
- disable:
- wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, WM831X_AUX_ENA, 0);
- out:
- mutex_unlock(&wm831x->auxadc_lock);
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm831x_auxadc_read);
- /**
- * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
- *
- * @wm831x: Device to read from.
- * @input: AUXADC input to read.
- */
- int wm831x_auxadc_read_uv(struct wm831x *wm831x, enum wm831x_auxadc input)
- {
- int ret;
- ret = wm831x_auxadc_read(wm831x, input);
- if (ret < 0)
- return ret;
- ret *= 1465;
- return ret;
- }
- EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv);
- static struct resource wm831x_dcdc1_resources[] = {
- {
- .start = WM831X_DC1_CONTROL_1,
- .end = WM831X_DC1_DVS_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_DC1,
- .end = WM831X_IRQ_UV_DC1,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "HC",
- .start = WM831X_IRQ_HC_DC1,
- .end = WM831X_IRQ_HC_DC1,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_dcdc2_resources[] = {
- {
- .start = WM831X_DC2_CONTROL_1,
- .end = WM831X_DC2_DVS_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_DC2,
- .end = WM831X_IRQ_UV_DC2,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "HC",
- .start = WM831X_IRQ_HC_DC2,
- .end = WM831X_IRQ_HC_DC2,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_dcdc3_resources[] = {
- {
- .start = WM831X_DC3_CONTROL_1,
- .end = WM831X_DC3_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_DC3,
- .end = WM831X_IRQ_UV_DC3,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_dcdc4_resources[] = {
- {
- .start = WM831X_DC4_CONTROL,
- .end = WM831X_DC4_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_DC4,
- .end = WM831X_IRQ_UV_DC4,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm8320_dcdc4_buck_resources[] = {
- {
- .start = WM831X_DC4_CONTROL,
- .end = WM832X_DC4_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_DC4,
- .end = WM831X_IRQ_UV_DC4,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_gpio_resources[] = {
- {
- .start = WM831X_IRQ_GPIO_1,
- .end = WM831X_IRQ_GPIO_16,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_isink1_resources[] = {
- {
- .start = WM831X_CURRENT_SINK_1,
- .end = WM831X_CURRENT_SINK_1,
- .flags = IORESOURCE_IO,
- },
- {
- .start = WM831X_IRQ_CS1,
- .end = WM831X_IRQ_CS1,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_isink2_resources[] = {
- {
- .start = WM831X_CURRENT_SINK_2,
- .end = WM831X_CURRENT_SINK_2,
- .flags = IORESOURCE_IO,
- },
- {
- .start = WM831X_IRQ_CS2,
- .end = WM831X_IRQ_CS2,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo1_resources[] = {
- {
- .start = WM831X_LDO1_CONTROL,
- .end = WM831X_LDO1_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO1,
- .end = WM831X_IRQ_UV_LDO1,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo2_resources[] = {
- {
- .start = WM831X_LDO2_CONTROL,
- .end = WM831X_LDO2_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO2,
- .end = WM831X_IRQ_UV_LDO2,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo3_resources[] = {
- {
- .start = WM831X_LDO3_CONTROL,
- .end = WM831X_LDO3_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO3,
- .end = WM831X_IRQ_UV_LDO3,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo4_resources[] = {
- {
- .start = WM831X_LDO4_CONTROL,
- .end = WM831X_LDO4_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO4,
- .end = WM831X_IRQ_UV_LDO4,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo5_resources[] = {
- {
- .start = WM831X_LDO5_CONTROL,
- .end = WM831X_LDO5_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO5,
- .end = WM831X_IRQ_UV_LDO5,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo6_resources[] = {
- {
- .start = WM831X_LDO6_CONTROL,
- .end = WM831X_LDO6_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO6,
- .end = WM831X_IRQ_UV_LDO6,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo7_resources[] = {
- {
- .start = WM831X_LDO7_CONTROL,
- .end = WM831X_LDO7_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO7,
- .end = WM831X_IRQ_UV_LDO7,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo8_resources[] = {
- {
- .start = WM831X_LDO8_CONTROL,
- .end = WM831X_LDO8_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO8,
- .end = WM831X_IRQ_UV_LDO8,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo9_resources[] = {
- {
- .start = WM831X_LDO9_CONTROL,
- .end = WM831X_LDO9_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO9,
- .end = WM831X_IRQ_UV_LDO9,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo10_resources[] = {
- {
- .start = WM831X_LDO10_CONTROL,
- .end = WM831X_LDO10_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- {
- .name = "UV",
- .start = WM831X_IRQ_UV_LDO10,
- .end = WM831X_IRQ_UV_LDO10,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_ldo11_resources[] = {
- {
- .start = WM831X_LDO11_ON_CONTROL,
- .end = WM831X_LDO11_SLEEP_CONTROL,
- .flags = IORESOURCE_IO,
- },
- };
- static struct resource wm831x_on_resources[] = {
- {
- .start = WM831X_IRQ_ON,
- .end = WM831X_IRQ_ON,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_power_resources[] = {
- {
- .name = "SYSLO",
- .start = WM831X_IRQ_PPM_SYSLO,
- .end = WM831X_IRQ_PPM_SYSLO,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "PWR SRC",
- .start = WM831X_IRQ_PPM_PWR_SRC,
- .end = WM831X_IRQ_PPM_PWR_SRC,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "USB CURR",
- .start = WM831X_IRQ_PPM_USB_CURR,
- .end = WM831X_IRQ_PPM_USB_CURR,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "BATT HOT",
- .start = WM831X_IRQ_CHG_BATT_HOT,
- .end = WM831X_IRQ_CHG_BATT_HOT,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "BATT COLD",
- .start = WM831X_IRQ_CHG_BATT_COLD,
- .end = WM831X_IRQ_CHG_BATT_COLD,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "BATT FAIL",
- .start = WM831X_IRQ_CHG_BATT_FAIL,
- .end = WM831X_IRQ_CHG_BATT_FAIL,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "OV",
- .start = WM831X_IRQ_CHG_OV,
- .end = WM831X_IRQ_CHG_OV,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "END",
- .start = WM831X_IRQ_CHG_END,
- .end = WM831X_IRQ_CHG_END,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "TO",
- .start = WM831X_IRQ_CHG_TO,
- .end = WM831X_IRQ_CHG_TO,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "MODE",
- .start = WM831X_IRQ_CHG_MODE,
- .end = WM831X_IRQ_CHG_MODE,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "START",
- .start = WM831X_IRQ_CHG_START,
- .end = WM831X_IRQ_CHG_START,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_rtc_resources[] = {
- {
- .name = "PER",
- .start = WM831X_IRQ_RTC_PER,
- .end = WM831X_IRQ_RTC_PER,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "ALM",
- .start = WM831X_IRQ_RTC_ALM,
- .end = WM831X_IRQ_RTC_ALM,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_status1_resources[] = {
- {
- .start = WM831X_STATUS_LED_1,
- .end = WM831X_STATUS_LED_1,
- .flags = IORESOURCE_IO,
- },
- };
- static struct resource wm831x_status2_resources[] = {
- {
- .start = WM831X_STATUS_LED_2,
- .end = WM831X_STATUS_LED_2,
- .flags = IORESOURCE_IO,
- },
- };
- static struct resource wm831x_touch_resources[] = {
- {
- .name = "TCHPD",
- .start = WM831X_IRQ_TCHPD,
- .end = WM831X_IRQ_TCHPD,
- .flags = IORESOURCE_IRQ,
- },
- {
- .name = "TCHDATA",
- .start = WM831X_IRQ_TCHDATA,
- .end = WM831X_IRQ_TCHDATA,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct resource wm831x_wdt_resources[] = {
- {
- .start = WM831X_IRQ_WDOG_TO,
- .end = WM831X_IRQ_WDOG_TO,
- .flags = IORESOURCE_IRQ,
- },
- };
- static struct mfd_cell wm8310_devs[] = {
- {
- .name = "wm831x-backup",
- },
- {
- .name = "wm831x-buckv",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
- .resources = wm831x_dcdc1_resources,
- },
- {
- .name = "wm831x-buckv",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
- .resources = wm831x_dcdc2_resources,
- },
- {
- .name = "wm831x-buckp",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
- .resources = wm831x_dcdc3_resources,
- },
- {
- .name = "wm831x-boostp",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
- .resources = wm831x_dcdc4_resources,
- },
- {
- .name = "wm831x-epe",
- .id = 1,
- },
- {
- .name = "wm831x-epe",
- .id = 2,
- },
- {
- .name = "wm831x-gpio",
- .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
- .resources = wm831x_gpio_resources,
- },
- {
- .name = "wm831x-hwmon",
- },
- {
- .name = "wm831x-isink",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
- .resources = wm831x_isink1_resources,
- },
- {
- .name = "wm831x-isink",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
- .resources = wm831x_isink2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
- .resources = wm831x_ldo1_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
- .resources = wm831x_ldo2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
- .resources = wm831x_ldo3_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
- .resources = wm831x_ldo4_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 5,
- .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
- .resources = wm831x_ldo5_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 6,
- .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
- .resources = wm831x_ldo6_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 7,
- .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
- .resources = wm831x_ldo7_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 8,
- .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
- .resources = wm831x_ldo8_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 9,
- .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
- .resources = wm831x_ldo9_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 10,
- .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
- .resources = wm831x_ldo10_resources,
- },
- {
- .name = "wm831x-alive-ldo",
- .id = 11,
- .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
- .resources = wm831x_ldo11_resources,
- },
- {
- .name = "wm831x-on",
- .num_resources = ARRAY_SIZE(wm831x_on_resources),
- .resources = wm831x_on_resources,
- },
- {
- .name = "wm831x-power",
- .num_resources = ARRAY_SIZE(wm831x_power_resources),
- .resources = wm831x_power_resources,
- },
- {
- .name = "wm831x-rtc",
- .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
- .resources = wm831x_rtc_resources,
- },
- {
- .name = "wm831x-status",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_status1_resources),
- .resources = wm831x_status1_resources,
- },
- {
- .name = "wm831x-status",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_status2_resources),
- .resources = wm831x_status2_resources,
- },
- {
- .name = "wm831x-watchdog",
- .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
- .resources = wm831x_wdt_resources,
- },
- };
- static struct mfd_cell wm8311_devs[] = {
- {
- .name = "wm831x-backup",
- },
- {
- .name = "wm831x-buckv",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
- .resources = wm831x_dcdc1_resources,
- },
- {
- .name = "wm831x-buckv",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
- .resources = wm831x_dcdc2_resources,
- },
- {
- .name = "wm831x-buckp",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
- .resources = wm831x_dcdc3_resources,
- },
- {
- .name = "wm831x-boostp",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
- .resources = wm831x_dcdc4_resources,
- },
- {
- .name = "wm831x-epe",
- .id = 1,
- },
- {
- .name = "wm831x-epe",
- .id = 2,
- },
- {
- .name = "wm831x-gpio",
- .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
- .resources = wm831x_gpio_resources,
- },
- {
- .name = "wm831x-hwmon",
- },
- {
- .name = "wm831x-isink",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
- .resources = wm831x_isink1_resources,
- },
- {
- .name = "wm831x-isink",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
- .resources = wm831x_isink2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
- .resources = wm831x_ldo1_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
- .resources = wm831x_ldo2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
- .resources = wm831x_ldo3_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
- .resources = wm831x_ldo4_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 5,
- .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
- .resources = wm831x_ldo5_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 7,
- .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
- .resources = wm831x_ldo7_resources,
- },
- {
- .name = "wm831x-alive-ldo",
- .id = 11,
- .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
- .resources = wm831x_ldo11_resources,
- },
- {
- .name = "wm831x-on",
- .num_resources = ARRAY_SIZE(wm831x_on_resources),
- .resources = wm831x_on_resources,
- },
- {
- .name = "wm831x-power",
- .num_resources = ARRAY_SIZE(wm831x_power_resources),
- .resources = wm831x_power_resources,
- },
- {
- .name = "wm831x-rtc",
- .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
- .resources = wm831x_rtc_resources,
- },
- {
- .name = "wm831x-status",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_status1_resources),
- .resources = wm831x_status1_resources,
- },
- {
- .name = "wm831x-status",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_status2_resources),
- .resources = wm831x_status2_resources,
- },
- {
- .name = "wm831x-touch",
- .num_resources = ARRAY_SIZE(wm831x_touch_resources),
- .resources = wm831x_touch_resources,
- },
- {
- .name = "wm831x-watchdog",
- .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
- .resources = wm831x_wdt_resources,
- },
- };
- static struct mfd_cell wm8312_devs[] = {
- {
- .name = "wm831x-backup",
- },
- {
- .name = "wm831x-buckv",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
- .resources = wm831x_dcdc1_resources,
- },
- {
- .name = "wm831x-buckv",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
- .resources = wm831x_dcdc2_resources,
- },
- {
- .name = "wm831x-buckp",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
- .resources = wm831x_dcdc3_resources,
- },
- {
- .name = "wm831x-boostp",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
- .resources = wm831x_dcdc4_resources,
- },
- {
- .name = "wm831x-epe",
- .id = 1,
- },
- {
- .name = "wm831x-epe",
- .id = 2,
- },
- {
- .name = "wm831x-gpio",
- .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
- .resources = wm831x_gpio_resources,
- },
- {
- .name = "wm831x-hwmon",
- },
- {
- .name = "wm831x-isink",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
- .resources = wm831x_isink1_resources,
- },
- {
- .name = "wm831x-isink",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
- .resources = wm831x_isink2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
- .resources = wm831x_ldo1_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
- .resources = wm831x_ldo2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
- .resources = wm831x_ldo3_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
- .resources = wm831x_ldo4_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 5,
- .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
- .resources = wm831x_ldo5_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 6,
- .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
- .resources = wm831x_ldo6_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 7,
- .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
- .resources = wm831x_ldo7_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 8,
- .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
- .resources = wm831x_ldo8_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 9,
- .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
- .resources = wm831x_ldo9_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 10,
- .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
- .resources = wm831x_ldo10_resources,
- },
- {
- .name = "wm831x-alive-ldo",
- .id = 11,
- .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
- .resources = wm831x_ldo11_resources,
- },
- {
- .name = "wm831x-on",
- .num_resources = ARRAY_SIZE(wm831x_on_resources),
- .resources = wm831x_on_resources,
- },
- {
- .name = "wm831x-power",
- .num_resources = ARRAY_SIZE(wm831x_power_resources),
- .resources = wm831x_power_resources,
- },
- {
- .name = "wm831x-rtc",
- .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
- .resources = wm831x_rtc_resources,
- },
- {
- .name = "wm831x-status",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_status1_resources),
- .resources = wm831x_status1_resources,
- },
- {
- .name = "wm831x-status",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_status2_resources),
- .resources = wm831x_status2_resources,
- },
- {
- .name = "wm831x-touch",
- .num_resources = ARRAY_SIZE(wm831x_touch_resources),
- .resources = wm831x_touch_resources,
- },
- {
- .name = "wm831x-watchdog",
- .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
- .resources = wm831x_wdt_resources,
- },
- };
- static struct mfd_cell wm8320_devs[] = {
- {
- .name = "wm831x-backup",
- },
- {
- .name = "wm831x-buckv",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
- .resources = wm831x_dcdc1_resources,
- },
- {
- .name = "wm831x-buckv",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
- .resources = wm831x_dcdc2_resources,
- },
- {
- .name = "wm831x-buckp",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
- .resources = wm831x_dcdc3_resources,
- },
- {
- .name = "wm831x-buckp",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
- .resources = wm8320_dcdc4_buck_resources,
- },
- {
- .name = "wm831x-gpio",
- .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
- .resources = wm831x_gpio_resources,
- },
- {
- .name = "wm831x-hwmon",
- },
- {
- .name = "wm831x-ldo",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
- .resources = wm831x_ldo1_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
- .resources = wm831x_ldo2_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 3,
- .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
- .resources = wm831x_ldo3_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 4,
- .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
- .resources = wm831x_ldo4_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 5,
- .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
- .resources = wm831x_ldo5_resources,
- },
- {
- .name = "wm831x-ldo",
- .id = 6,
- .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
- .resources = wm831x_ldo6_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 7,
- .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
- .resources = wm831x_ldo7_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 8,
- .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
- .resources = wm831x_ldo8_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 9,
- .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
- .resources = wm831x_ldo9_resources,
- },
- {
- .name = "wm831x-aldo",
- .id = 10,
- .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
- .resources = wm831x_ldo10_resources,
- },
- {
- .name = "wm831x-alive-ldo",
- .id = 11,
- .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
- .resources = wm831x_ldo11_resources,
- },
- {
- .name = "wm831x-on",
- .num_resources = ARRAY_SIZE(wm831x_on_resources),
- .resources = wm831x_on_resources,
- },
- {
- .name = "wm831x-rtc",
- .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
- .resources = wm831x_rtc_resources,
- },
- {
- .name = "wm831x-status",
- .id = 1,
- .num_resources = ARRAY_SIZE(wm831x_status1_resources),
- .resources = wm831x_status1_resources,
- },
- {
- .name = "wm831x-status",
- .id = 2,
- .num_resources = ARRAY_SIZE(wm831x_status2_resources),
- .resources = wm831x_status2_resources,
- },
- {
- .name = "wm831x-watchdog",
- .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
- .resources = wm831x_wdt_resources,
- },
- };
- static struct mfd_cell backlight_devs[] = {
- {
- .name = "wm831x-backlight",
- },
- };
- /*
- * Instantiate the generic non-control parts of the device.
- */
- static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
- {
- struct wm831x_pdata *pdata = wm831x->dev->platform_data;
- int rev;
- enum wm831x_parent parent;
- int ret;
- mutex_init(&wm831x->io_lock);
- mutex_init(&wm831x->key_lock);
- mutex_init(&wm831x->auxadc_lock);
- dev_set_drvdata(wm831x->dev, wm831x);
- ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
- goto err;
- }
- if (ret != 0x6204) {
- dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
- ret = -EINVAL;
- goto err;
- }
- ret = wm831x_reg_read(wm831x, WM831X_REVISION);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
- goto err;
- }
- rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
- ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
- goto err;
- }
- /* Some engineering samples do not have the ID set, rely on
- * the device being registered correctly.
- */
- if (ret == 0) {
- dev_info(wm831x->dev, "Device is an engineering sample\n");
- ret = id;
- }
- switch (ret) {
- case WM8310:
- parent = WM8310;
- wm831x->num_gpio = 16;
- dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
- break;
- case WM8311:
- parent = WM8311;
- wm831x->num_gpio = 16;
- dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
- break;
- case WM8312:
- parent = WM8312;
- wm831x->num_gpio = 16;
- dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
- break;
- case WM8320:
- parent = WM8320;
- wm831x->num_gpio = 12;
- dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
- break;
- default:
- dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
- ret = -EINVAL;
- goto err;
- }
- /* This will need revisiting in future but is OK for all
- * current parts.
- */
- if (parent != id)
- dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
- id);
- /* Bootstrap the user key */
- ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
- if (ret < 0) {
- dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
- goto err;
- }
- if (ret != 0) {
- dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
- ret);
- wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
- }
- wm831x->locked = 1;
- if (pdata && pdata->pre_init) {
- ret = pdata->pre_init(wm831x);
- if (ret != 0) {
- dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
- goto err;
- }
- }
- ret = wm831x_irq_init(wm831x, irq);
- if (ret != 0)
- goto err;
- /* The core device is up, instantiate the subdevices. */
- switch (parent) {
- case WM8310:
- ret = mfd_add_devices(wm831x->dev, -1,
- wm8310_devs, ARRAY_SIZE(wm8310_devs),
- NULL, wm831x->irq_base);
- break;
- case WM8311:
- ret = mfd_add_devices(wm831x->dev, -1,
- wm8311_devs, ARRAY_SIZE(wm8311_devs),
- NULL, wm831x->irq_base);
- break;
- case WM8312:
- ret = mfd_add_devices(wm831x->dev, -1,
- wm8312_devs, ARRAY_SIZE(wm8312_devs),
- NULL, wm831x->irq_base);
- break;
- case WM8320:
- ret = mfd_add_devices(wm831x->dev, -1,
- wm8320_devs, ARRAY_SIZE(wm8320_devs),
- NULL, 0);
- break;
- default:
- /* If this happens the bus probe function is buggy */
- BUG();
- }
- if (ret != 0) {
- dev_err(wm831x->dev, "Failed to add children\n");
- goto err_irq;
- }
- if (pdata && pdata->backlight) {
- /* Treat errors as non-critical */
- ret = mfd_add_devices(wm831x->dev, -1, backlight_devs,
- ARRAY_SIZE(backlight_devs), NULL,
- wm831x->irq_base);
- if (ret < 0)
- dev_err(wm831x->dev, "Failed to add backlight: %d\n",
- ret);
- }
- wm831x_otp_init(wm831x);
- if (pdata && pdata->post_init) {
- ret = pdata->post_init(wm831x);
- if (ret != 0) {
- dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
- goto err_irq;
- }
- }
- return 0;
- err_irq:
- wm831x_irq_exit(wm831x);
- err:
- mfd_remove_devices(wm831x->dev);
- kfree(wm831x);
- return ret;
- }
- static void wm831x_device_exit(struct wm831x *wm831x)
- {
- wm831x_otp_exit(wm831x);
- mfd_remove_devices(wm831x->dev);
- wm831x_irq_exit(wm831x);
- kfree(wm831x);
- }
- static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg,
- int bytes, void *dest)
- {
- struct i2c_client *i2c = wm831x->control_data;
- int ret;
- u16 r = cpu_to_be16(reg);
- ret = i2c_master_send(i2c, (unsigned char *)&r, 2);
- if (ret < 0)
- return ret;
- if (ret != 2)
- return -EIO;
- ret = i2c_master_recv(i2c, dest, bytes);
- if (ret < 0)
- return ret;
- if (ret != bytes)
- return -EIO;
- return 0;
- }
- /* Currently we allocate the write buffer on the stack; this is OK for
- * small writes - if we need to do large writes this will need to be
- * revised.
- */
- static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg,
- int bytes, void *src)
- {
- struct i2c_client *i2c = wm831x->control_data;
- unsigned char msg[bytes + 2];
- int ret;
- reg = cpu_to_be16(reg);
- memcpy(&msg[0], ®, 2);
- memcpy(&msg[2], src, bytes);
- ret = i2c_master_send(i2c, msg, bytes + 2);
- if (ret < 0)
- return ret;
- if (ret < bytes + 2)
- return -EIO;
- return 0;
- }
- static int wm831x_i2c_probe(struct i2c_client *i2c,
- const struct i2c_device_id *id)
- {
- struct wm831x *wm831x;
- wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
- if (wm831x == NULL) {
- kfree(i2c);
- return -ENOMEM;
- }
- i2c_set_clientdata(i2c, wm831x);
- wm831x->dev = &i2c->dev;
- wm831x->control_data = i2c;
- wm831x->read_dev = wm831x_i2c_read_device;
- wm831x->write_dev = wm831x_i2c_write_device;
- return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
- }
- static int wm831x_i2c_remove(struct i2c_client *i2c)
- {
- struct wm831x *wm831x = i2c_get_clientdata(i2c);
- wm831x_device_exit(wm831x);
- return 0;
- }
- static const struct i2c_device_id wm831x_i2c_id[] = {
- { "wm8310", WM8310 },
- { "wm8311", WM8311 },
- { "wm8312", WM8312 },
- { "wm8320", WM8320 },
- { }
- };
- MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
- static struct i2c_driver wm831x_i2c_driver = {
- .driver = {
- .name = "wm831x",
- .owner = THIS_MODULE,
- },
- .probe = wm831x_i2c_probe,
- .remove = wm831x_i2c_remove,
- .id_table = wm831x_i2c_id,
- };
- static int __init wm831x_i2c_init(void)
- {
- int ret;
- ret = i2c_add_driver(&wm831x_i2c_driver);
- if (ret != 0)
- pr_err("Failed to register wm831x I2C driver: %d\n", ret);
- return ret;
- }
- subsys_initcall(wm831x_i2c_init);
- static void __exit wm831x_i2c_exit(void)
- {
- i2c_del_driver(&wm831x_i2c_driver);
- }
- module_exit(wm831x_i2c_exit);
- MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Mark Brown");
|