Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756221AbZFZXJL (ORCPT ); Fri, 26 Jun 2009 19:09:11 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752666AbZFZXI6 (ORCPT ); Fri, 26 Jun 2009 19:08:58 -0400 Received: from mail-qy0-f193.google.com ([209.85.221.193]:56424 "EHLO mail-qy0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752005AbZFZXI5 (ORCPT ); Fri, 26 Jun 2009 19:08:57 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer; b=bCFZBZH3/oH8iwStTYtTUSCFssehwbbq8gQfo1rsu6lT6tL2DRH3QgFTXXsxzsB7nZ wo1Q5USJVxgya6j4RbwrNEVdkCD6azUi0qDNvRpfuzVcBRV5C9bIyGvL6k1mE7MVLU+B 8nqJKh/NrM9kKhubPZOAsMvzPGu51tyvcxX9w= Subject: [PATCHv2 2/2] PCAP regulator driver (for 2.6.32) From: Daniel Ribeiro To: Mark Brown , Liam Girdwood , linux-kernel Cc: Eric Miao , David Brownell , Pierre Ossman , openezx-devel , linux-arm-kernel Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-3/wAJgeAKO3v6k9nQuZe" Date: Fri, 26 Jun 2009 20:08:41 -0300 Message-Id: <1246057721.10360.318.camel@brutus> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 11081 Lines: 411 --=-3/wAJgeAKO3v6k9nQuZe Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Changed: Removed workaround for regulator use_count issues. =3D=3D=3D CUT HERE =3D=3D=3D Add (partial) support for the voltage regulators on the PCAP2 PMIC. Signed-off-by: Daniel Ribeiro --- drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 + drivers/regulator/pcap-regulator.c | 329 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 337 insertions(+), 0 deletions(-) diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index f431779..da7483e 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -117,4 +117,11 @@ config REGULATOR_LP3971 Say Y here to support the voltage regulators and convertors on National Semiconductors LP3971 PMIC =20 +config REGULATOR_PCAP + tristate "PCAP2 regulator driver" + depends on EZX_PCAP + help + This driver provides support for the voltage regulators of the + PCAP2 PMIC. + endif diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 4d762c4..3a9748f 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -16,5 +16,6 @@ obj-$(CONFIG_REGULATOR_WM8350) +=3D wm8350-regulator.o obj-$(CONFIG_REGULATOR_WM8400) +=3D wm8400-regulator.o obj-$(CONFIG_REGULATOR_DA903X) +=3D da903x.o obj-$(CONFIG_REGULATOR_PCF50633) +=3D pcf50633-regulator.o +obj-$(CONFIG_REGULATOR_PCAP) +=3D pcap-regulator.o =20 ccflags-$(CONFIG_REGULATOR_DEBUG) +=3D -DDEBUG diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-re= gulator.c new file mode 100644 index 0000000..7ebaa6a --- /dev/null +++ b/drivers/regulator/pcap-regulator.c @@ -0,0 +1,329 @@ +/* + * PCAP2 Regulator Driver + * + * Copyright (c) 2009 Daniel Ribeiro + * + * This program is free software; you can redistribute it and/or modify i= t + * under the terms of the GNU General Public License as published by th= e + * Free Software Foundation; either version 2 of the License, or (at you= r + * option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static const u16 V1_table[] =3D { + 2775, 1275, 1600, 1725, 1825, 1925, 2075, 2275, +}; + +static const u16 V2_table[] =3D { + 2500, 2775, +}; + +static const u16 V3_table[] =3D { + 1075, 1275, 1550, 1725, 1876, 1950, 2075, 2275, +}; + +static const u16 V4_table[] =3D { + 1275, 1550, 1725, 1875, 1950, 2075, 2275, 2775, +}; + +static const u16 V5_table[] =3D { + 1875, 2275, 2475, 2775, +}; + +static const u16 V6_table[] =3D { + 2475, 2775, +}; + +static const u16 V7_table[] =3D { + 1875, 2775, +}; + +#define V8_table V4_table + +static const u16 V9_table[] =3D { + 1575, 1875, 2475, 2775, +}; + +static const u16 V10_table[] =3D { + 5000, +}; + +static const u16 VAUX1_table[] =3D { + 1875, 2475, 2775, 3000, +}; + +#define VAUX2_table VAUX1_table + +static const u16 VAUX3_table[] =3D { + 1200, 1200, 1200, 1200, 1400, 1600, 1800, 2000, + 2200, 2400, 2600, 2800, 3000, 3200, 3400, 3600, +}; + +static const u16 VAUX4_table[] =3D { + 1800, 1800, 3000, 5000, +}; + +static const u16 VSIM_table[] =3D { + 1875, 3000, +}; + +static const u16 VSIM2_table[] =3D { + 1875, +}; + +static const u16 VVIB_table[] =3D { + 1300, 1800, 2000, 3000, +}; + +static const u16 SW1_table[] =3D { + 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, + 1300, 1350, 1400, 1450, 1500, 1600, 1875, 2250, +}; + +#define SW2_table SW1_table + +static const u16 SW3_table[] =3D { + 4000, 4500, 5000, 5500, +}; + +struct pcap_regulator { + const u8 reg; + const u8 en; + const u8 index; + const u8 stby; + const u8 lowpwr; + const u8 n_voltages; + const u16 *voltage_table; +}; + +#define NA 0xff + +#define VREG_INFO(_vreg, _reg, _en, _index, _stby, _lowpwr) \ + [_vreg] =3D { \ + .reg =3D _reg, \ + .en =3D _en, \ + .index =3D _index, \ + .stby =3D _stby, \ + .lowpwr =3D _lowpwr, \ + .n_voltages =3D ARRAY_SIZE(_vreg##_table), \ + .voltage_table =3D _vreg##_table, \ + } + +static struct pcap_regulator vreg_table[] =3D { + VREG_INFO(V1, PCAP_REG_VREG1, 1, 2, 18, 0), + VREG_INFO(V2, PCAP_REG_VREG1, 5, 6, 19, 22), + VREG_INFO(V3, PCAP_REG_VREG1, 7, 8, 20, 23), + VREG_INFO(V4, PCAP_REG_VREG1, 11, 12, 21, 24), + /* V5 STBY and LOWPWR are on PCAP_REG_VREG2 */ + VREG_INFO(V5, PCAP_REG_VREG1, 15, 16, 12, 19), + + VREG_INFO(V6, PCAP_REG_VREG2, 1, 2, 14, 20), + VREG_INFO(V7, PCAP_REG_VREG2, 3, 4, 15, 21), + VREG_INFO(V8, PCAP_REG_VREG2, 5, 6, 16, 22), + VREG_INFO(V9, PCAP_REG_VREG2, 9, 10, 17, 23), + VREG_INFO(V10, PCAP_REG_VREG2, 10, NA, 18, 24), + + VREG_INFO(VAUX1, PCAP_REG_AUXVREG, 1, 2, 22, 23), + /* VAUX2 ... VSIM2 STBY and LOWPWR are on PCAP_REG_LOWPWR */ + VREG_INFO(VAUX2, PCAP_REG_AUXVREG, 4, 5, 0, 1), + VREG_INFO(VAUX3, PCAP_REG_AUXVREG, 7, 8, 2, 3), + VREG_INFO(VAUX4, PCAP_REG_AUXVREG, 12, 13, 4, 5), + VREG_INFO(VSIM, PCAP_REG_AUXVREG, 17, 18, NA, 6), + VREG_INFO(VSIM2, PCAP_REG_AUXVREG, 16, NA, NA, 7), + VREG_INFO(VVIB, PCAP_REG_AUXVREG, 19, 20, NA, NA), + + VREG_INFO(SW1, PCAP_REG_SWCTRL, 1, 2, NA, NA), + VREG_INFO(SW2, PCAP_REG_SWCTRL, 6, 7, NA, NA), + /* SW3 STBY is on PCAP_REG_AUXVREG */ + VREG_INFO(SW3, PCAP_REG_SWCTRL, 11, 12, 24, NA), + + /* SWxS used to control SWx voltage on standby */ +/* VREG_INFO(SW1S, PCAP_REG_LOWPWR, NA, 12, NA, NA), + VREG_INFO(SW2S, PCAP_REG_LOWPWR, NA, 20, NA, NA), */ +}; + +static int pcap_regulator_set_voltage(struct regulator_dev *rdev, + int min_uV, int max_uV) +{ + struct pcap_regulator *vreg =3D &vreg_table[rdev_get_id(rdev)]; + void *pcap =3D rdev_get_drvdata(rdev); + int uV; + u32 tmp; + u8 i; + + if (vreg->n_voltages =3D=3D 1) + return -EINVAL; + + for (i =3D 0; i < vreg->n_voltages; i++) { + /* For V1 the first is not the best match */ + if (i =3D=3D 0 && rdev_get_id(rdev) =3D=3D V1) + i =3D 1; + else if (i + 1 =3D=3D vreg->n_voltages && rdev_get_id(rdev) =3D=3D V1) + i =3D 0; + + uV =3D vreg->voltage_table[i] * 1000; + if (min_uV <=3D uV && uV <=3D max_uV) { + ezx_pcap_read(pcap, vreg->reg, &tmp); + tmp &=3D ~((vreg->n_voltages - 1) << vreg->index); + tmp |=3D i << vreg->index; + ezx_pcap_write(pcap, vreg->reg, tmp); + return 0; + } + if (i =3D=3D 0 && rdev_get_id(rdev) =3D=3D V1) + i =3D vreg->n_voltages - 1; + } + + return -EINVAL; +} + +static int pcap_regulator_get_voltage(struct regulator_dev *rdev) +{ + struct pcap_regulator *vreg =3D &vreg_table[rdev_get_id(rdev)]; + void *pcap =3D rdev_get_drvdata(rdev); + u32 tmp; + int mV; + + if (vreg->n_voltages =3D=3D 1) + return vreg->voltage_table[0] * 1000; + + ezx_pcap_read(pcap, vreg->reg, &tmp); + tmp =3D ((tmp >> vreg->index) & (vreg->n_voltages - 1)); + mV =3D vreg->voltage_table[tmp]; + + return mV * 1000; +} + +static int pcap_regulator_enable(struct regulator_dev *rdev) +{ + struct pcap_regulator *vreg =3D &vreg_table[rdev_get_id(rdev)]; + void *pcap =3D rdev_get_drvdata(rdev); + u32 tmp; + + if (vreg->en =3D=3D NA) + return -EINVAL; + + ezx_pcap_read(pcap, vreg->reg, &tmp); + tmp |=3D (1 << vreg->en); + ezx_pcap_write(pcap, vreg->reg, tmp); + + return 0; +} + +static int pcap_regulator_disable(struct regulator_dev *rdev) +{ + struct pcap_regulator *vreg =3D &vreg_table[rdev_get_id(rdev)]; + void *pcap =3D rdev_get_drvdata(rdev); + u32 tmp; + + if (vreg->en =3D=3D NA) + return -EINVAL; + + ezx_pcap_read(pcap, vreg->reg, &tmp); + tmp &=3D ~(1 << vreg->en); + ezx_pcap_write(pcap, vreg->reg, tmp); + + return 0; +} + +static int pcap_regulator_is_enabled(struct regulator_dev *rdev) +{ + struct pcap_regulator *vreg =3D &vreg_table[rdev_get_id(rdev)]; + void *pcap =3D rdev_get_drvdata(rdev); + u32 tmp; + + if (vreg->en =3D=3D NA) + return -EINVAL; + + ezx_pcap_read(pcap, vreg->reg, &tmp); + return (tmp >> vreg->en) & 1; +} + +static int pcap_regulator_list_voltage(struct regulator_dev *rdev, + unsigned int index) +{ + struct pcap_regulator *vreg =3D &vreg_table[rdev_get_id(rdev)]; + + return vreg->voltage_table[index] * 1000; +} + +static struct regulator_ops pcap_regulator_ops =3D { + .list_voltage =3D pcap_regulator_list_voltage, + .set_voltage =3D pcap_regulator_set_voltage, + .get_voltage =3D pcap_regulator_get_voltage, + .enable =3D pcap_regulator_enable, + .disable =3D pcap_regulator_disable, + .is_enabled =3D pcap_regulator_is_enabled, +}; + +#define VREG(_vreg) \ + [_vreg] =3D { \ + .name =3D #_vreg, \ + .id =3D _vreg, \ + .n_voltages =3D ARRAY_SIZE(_vreg##_table), \ + .ops =3D &pcap_regulator_ops, \ + .type =3D REGULATOR_VOLTAGE, \ + .owner =3D THIS_MODULE, \ + } + +static struct regulator_desc pcap_regulators[] =3D { + VREG(V1), VREG(V2), VREG(V3), VREG(V4), VREG(V5), VREG(V6), VREG(V7), + VREG(V8), VREG(V9), VREG(V10), VREG(VAUX1), VREG(VAUX2), VREG(VAUX3), + VREG(VAUX4), VREG(VSIM), VREG(VSIM2), VREG(VVIB), VREG(SW1), VREG(SW2), +}; + +static int __devinit pcap_regulator_probe(struct platform_device *pdev) +{ + struct regulator_dev *rdev; + void *pcap =3D platform_get_drvdata(pdev); + + rdev =3D regulator_register(&pcap_regulators[pdev->id], &pdev->dev, + pdev->dev.platform_data, pcap); + if (IS_ERR(rdev)) + return PTR_ERR(rdev); + + platform_set_drvdata(pdev, rdev); + + return 0; +} + +static int __devexit pcap_regulator_remove(struct platform_device *pdev) +{ + struct regulator_dev *rdev =3D platform_get_drvdata(pdev); + + regulator_unregister(rdev); + + return 0; +} + +static struct platform_driver pcap_regulator_driver =3D { + .driver =3D { + .name =3D "pcap-regulator", + }, + .probe =3D pcap_regulator_probe, + .remove =3D __devexit_p(pcap_regulator_remove), +}; + +static int __init pcap_regulator_init(void) +{ + return platform_driver_register(&pcap_regulator_driver); +} + +static void __exit pcap_regulator_exit(void) +{ + platform_driver_unregister(&pcap_regulator_driver); +} + +module_init(pcap_regulator_init); +module_exit(pcap_regulator_exit); + +MODULE_AUTHOR("Daniel Ribeiro "); +MODULE_DESCRIPTION("PCAP2 Regulator Driver"); +MODULE_LICENSE("GPL"); --=20 tg: (69e76aa..) ezx/pcap_regulator (depends on: ezx/local/pcap) --=20 Daniel Ribeiro --=-3/wAJgeAKO3v6k9nQuZe Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Esta =?ISO-8859-1?Q?=E9?= uma parte de mensagem assinada digitalmente -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkpFVPkACgkQw3OYl0G0liRatQCdFK4t7Ud2UINPjqhiADI4Oden hWgAnRiXe9KC2cBtAWldHVZfIkJ+gh5K =B1Va -----END PGP SIGNATURE----- --=-3/wAJgeAKO3v6k9nQuZe-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/