summaryrefslogtreecommitdiff
path: root/drivers/mfd
diff options
context:
space:
mode:
authorLaxman Dewangan <ldewangan@nvidia.com>2013-11-13 18:53:12 +0530
committerLaxman Dewangan <ldewangan@nvidia.com>2013-11-13 20:50:25 -0800
commitfaee6aeedb921c67156cb3ad6ab2bf769f972cdb (patch)
treeea5fc66f70ac6246c901ee3cf946cc18f445167e /drivers/mfd
parent245c6bf7488921e31530952e20422dddfd2b6c44 (diff)
mfd: as3722: remove unused core and header file
as3722-core.c, as3722-test.c and as3722-reg.h is no more used and hence removing this code to avoid duplication of files. The functionality is moved to as3722.c which is already aligned with mainline driver. Change-Id: I8547f42baaf1718690f1ccbe7371d0fbc5f08626 Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Reviewed-on: http://git-master/r/330344 Reviewed-by: Automatic_Commit_Validation_User
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/as3722-core.c427
-rw-r--r--drivers/mfd/as3722-test.c430
2 files changed, 0 insertions, 857 deletions
diff --git a/drivers/mfd/as3722-core.c b/drivers/mfd/as3722-core.c
deleted file mode 100644
index 2d0530cea184..000000000000
--- a/drivers/mfd/as3722-core.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * as3722-core.c - core driver for AS3722 PMICs
- *
- * Copyright (C) 2013 ams AG
- * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
- *
- * Author: Florian Lobmaier <florian.lobmaier@ams.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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/i2c.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/regmap.h>
-#include <linux/err.h>
-#include <linux/delay.h>
-#include <linux/mfd/core.h>
-#include <linux/interrupt.h>
-#include <linux/mfd/as3722-reg.h>
-#include <linux/mfd/as3722-plat.h>
-
-#define AS3722_DRIVER_VERSION "v0.9.0"
-
-enum as3722_ids {
- AS3722_PINCTRL_ID,
- AS3722_REGULATOR_ID,
- AS3722_RTC_ID,
- AS3722_ADC,
- AS3722_POWER_OFF_ID,
- AS3722_CLK_ID,
-};
-
-static const struct resource as3722_rtc_resource[] = {
- {
- .name = "as3722-rtc-alarm",
- .start = AS3722_IRQ_RTC_ALARM,
- .end = AS3722_IRQ_RTC_ALARM,
- .flags = IORESOURCE_IRQ,
- },
-};
-
-static const struct resource as3722_adc_resource[] = {
- {
- .name = "as3722-adc",
- .start = AS3722_IRQ_ADC,
- .end = AS3722_IRQ_ADC,
- .flags = IORESOURCE_IRQ,
- },
-};
-
-static struct mfd_cell as3722_devs[] = {
- {
- .name = "as3722-pinctrl",
- .id = AS3722_PINCTRL_ID,
- },
- {
- .name = "as3722-regulator",
- .id = AS3722_REGULATOR_ID,
- },
- {
- .name = "as3722-clk",
- .id = AS3722_CLK_ID,
- },
- {
- .name = "as3722-rtc",
- .num_resources = ARRAY_SIZE(as3722_rtc_resource),
- .resources = as3722_rtc_resource,
- .id = AS3722_RTC_ID,
- },
- {
- .name = "as3722-adc-extcon",
- .num_resources = ARRAY_SIZE(as3722_adc_resource),
- .resources = as3722_adc_resource,
- .id = AS3722_ADC,
- },
- {
- .name = "as3722-power-off",
- .id = AS3722_POWER_OFF_ID,
- },
-};
-
-static const struct regmap_irq as3722_irqs[] = {
- /* INT1 IRQs */
- [AS3722_IRQ_LID] = {
- .mask = AS3722_IRQ_MASK_LID,
- },
- [AS3722_IRQ_ACOK] = {
- .mask = AS3722_IRQ_MASK_ACOK,
- },
- [AS3722_IRQ_CORE_PWRREQ] = {
- .mask = AS3722_IRQ_MASK_CORE_PWRREQ,
- },
- [AS3722_IRQ_SD0] = {
- .mask = AS3722_IRQ_MASK_SD0,
- },
- [AS3722_IRQ_ONKEY_LONG] = {
- .mask = AS3722_IRQ_MASK_ONKEY_LONG,
- },
- [AS3722_IRQ_ONKEY] = {
- .mask = AS3722_IRQ_MASK_ONKEY,
- },
- [AS3722_IRQ_OVTMP] = {
- .mask = AS3722_IRQ_MASK_OVTMP,
- },
- [AS3722_IRQ_LOWBAT] = {
- .mask = AS3722_IRQ_MASK_LOWBAT,
- },
- /* INT2 IRQs */
- [AS3722_IRQ_RTC_REP] = {
- .mask = AS3722_IRQ_MASK_RTC_REP,
- .reg_offset = 1,
- },
- /* INT3 IRQs */
- [AS3722_IRQ_RTC_ALARM] = {
- .mask = AS3722_IRQ_MASK_RTC_ALARM,
- .reg_offset = 2,
- },
- [AS3722_IRQ_RTC_GPIO1] = {
- .mask = AS3722_IRQ_MASK_GPIO_EDGE1,
- .type_rising_mask = AS3722_IRQ_MASK_GPIO_EDGE1,
- .type_falling_mask = AS3722_IRQ_MASK_GPIO_EDGE1,
- .reg_offset = 2,
- },
- [AS3722_IRQ_RTC_GPIO2] = {
- .mask = AS3722_IRQ_MASK_GPIO_EDGE2,
- .type_rising_mask = AS3722_IRQ_MASK_GPIO_EDGE2,
- .type_falling_mask = AS3722_IRQ_MASK_GPIO_EDGE2,
- .reg_offset = 2,
- },
- [AS3722_IRQ_RTC_GPIO3] = {
- .mask = AS3722_IRQ_MASK_GPIO_EDGE3,
- .type_rising_mask = AS3722_IRQ_MASK_GPIO_EDGE3,
- .type_falling_mask = AS3722_IRQ_MASK_GPIO_EDGE3,
- .reg_offset = 2,
- },
- [AS3722_IRQ_RTC_GPIO4] = {
- .mask = AS3722_IRQ_MASK_GPIO_EDGE4,
- .type_rising_mask = AS3722_IRQ_MASK_GPIO_EDGE4,
- .type_falling_mask = AS3722_IRQ_MASK_GPIO_EDGE4,
- .reg_offset = 2,
- },
- [AS3722_IRQ_RTC_GPIO5] = {
- .mask = AS3722_IRQ_MASK_GPIO_EDGE5,
- .type_rising_mask = AS3722_IRQ_MASK_GPIO_EDGE5,
- .type_falling_mask = AS3722_IRQ_MASK_GPIO_EDGE5,
- .reg_offset = 2,
- },
- [AS3722_IRQ_WATCHDOG] = {
- .mask = AS3722_IRQ_MASK_WATCHDOG,
- .reg_offset = 2,
- },
- [AS3722_IRQ_ADC] = {
- .mask = AS3722_IRQ_MASK_ADC,
- .reg_offset = 3,
- },
-};
-
-static struct regmap_irq_chip as3722_irq_chip = {
- .name = "as3722",
- .irqs = as3722_irqs,
- .num_irqs = ARRAY_SIZE(as3722_irqs),
- .num_regs = 4,
- .status_base = AS3722_INTERRUPTSTATUS1_REG,
- .mask_base = AS3722_INTERRUPTMASK1_REG,
-};
-
-static void as3722_reg_init(struct as3722 *as3722,
- struct as3722_reg_init *reg_data) {
- int ret;
-
- while (reg_data->reg != AS3722_REG_INIT_TERMINATE) {
- ret = as3722_reg_write(as3722, reg_data->reg, reg_data->val);
- if (ret) {
- dev_err(as3722->dev,
- "reg setup failed: %d\n", ret);
- return;
- }
- reg_data++;
- }
-}
-
-int as3722_read_adc(struct as3722 *as3722,
- enum as3722_adc_channel channel,
- enum as3722_adc_source source) {
- /*FIXME: not implemented yet*/
- return 0;
-}
-EXPORT_SYMBOL_GPL(as3722_read_adc);
-
-static int as3722_init(struct as3722 *as3722,
- struct as3722_platform_data *pdata, int irq) {
- u32 reg;
- int ret;
-
- /* Check that this is actually a AS3722 */
- ret = regmap_read(as3722->regmap, AS3722_ADDR_ASIC_ID1, &reg);
- if (ret != 0) {
- dev_err(as3722->dev,
- "Chip ID register read failed\n");
- return -EIO;
- }
- if (reg != AS3722_DEVICE_ID) {
- dev_err(as3722->dev,
- "Device is not an AS3722, ID is 0x%x\n"
- , reg);
- return -ENODEV;
- }
-
- ret = regmap_read(as3722->regmap, AS3722_ADDR_ASIC_ID2, &reg);
- if (ret < 0) {
- dev_err(as3722->dev,
- "ID2 register read failed: %d\n", ret);
- return ret;
- }
- dev_info(as3722->dev, "AS3722 with revision %x found\n",
- reg);
-
- /* do some initial platform register setup */
- if (pdata->core_init_data)
- as3722_reg_init(as3722, pdata->core_init_data);
-
- /* enable pullups if required */
- if (pdata->use_internal_int_pullup == 1)
- as3722_set_bits(as3722, AS3722_IOVOLTAGE_REG,
- AS3722_INT_PULLUP_MASK, AS3722_INT_PULLUP_ON);
- else
- as3722_set_bits(as3722, AS3722_IOVOLTAGE_REG,
- AS3722_INT_PULLUP_MASK, AS3722_INT_PULLUP_OFF);
- if (pdata->use_internal_i2c_pullup == 1)
- as3722_set_bits(as3722, AS3722_IOVOLTAGE_REG,
- AS3722_I2C_PULLUP_MASK, AS3722_I2C_PULLUP_ON);
- else
- as3722_set_bits(as3722, AS3722_IOVOLTAGE_REG,
- AS3722_I2C_PULLUP_MASK, AS3722_I2C_PULLUP_OFF);
-
- return 0;
-}
-
-static bool as3722_readable(struct device *dev, unsigned int reg)
-{
- switch (reg) {
- case 0x00 ... 0x06:
- case 0x08 ... 0x17:
- case 0x19 ... 0x24:
- case 0x27 ... 0x42:
- case 0x46:
- case 0x48 ... 0x4A:
- case 0x4D ... 0x55:
- case 0x57 ... 0x6D:
- case 0x73 ... 0x7D:
- case 0x80 ... 0x8A:
- case 0x90 ... 0x91:
- case 0xA7 ... 0xF3:
- return true;
- default:
- return false;
- }
-}
-
-static bool as3722_writeable(struct device *dev, unsigned int reg)
-{
- switch (reg) {
- case 0x00 ... 0x06:
- case 0x08 ... 0x17:
- case 0x19 ... 0x20:
- case 0x22 ... 0x24:
- case 0x27 ... 0x42:
- case 0x46:
- case 0x48 ... 0x4A:
- case 0x4D ... 0x55:
- case 0x57 ... 0x6D:
- case 0x74 ... 0x7D:
- case 0x80 ... 0x81:
- case 0x86 ... 0x8A:
- case 0xA7 ... 0xF3:
- return true;
- default:
- return false;
- }
-}
-
-static bool as3722_volatile(struct device *dev, unsigned int reg)
-{
- switch (reg) {
- case AS3722_SD0_VOLTAGE_REG ... AS3722_LDO11_VOLTAGE_REG:
- case AS3722_SD_CONTROL_REG ... AS3722_LDOCONTROL1_REG:
- return false;
- default:
- return true;
- }
-}
-
-const struct regmap_config as3722_regmap_config = {
- .reg_bits = 8,
- .val_bits = 8,
-
- .cache_type = REGCACHE_RBTREE,
-
- .max_register = AS3722_MAX_REGISTER,
- .readable_reg = as3722_readable,
- .writeable_reg = as3722_writeable,
- .volatile_reg = as3722_volatile,
-};
-
-static int as3722_i2c_probe(struct i2c_client *i2c,
- const struct i2c_device_id *id) {
- struct as3722 *as3722;
- struct as3722_platform_data *pdata;
- int irq_flags;
- int ret;
-
- pdata = dev_get_platdata(&i2c->dev);
- if (!pdata) {
- dev_err(&i2c->dev, "as3722 requires platform data\n");
- return -EINVAL;
- }
-
- as3722 = devm_kzalloc(&i2c->dev, sizeof(struct as3722), GFP_KERNEL);
- if (as3722 == NULL) {
- dev_err(&i2c->dev, "mem alloc for as3722 failed\n");
- return -ENOMEM;
- }
-
- as3722->dev = &i2c->dev;
- as3722->chip_irq = i2c->irq;
- i2c_set_clientdata(i2c, as3722);
-
- as3722->regmap = devm_regmap_init_i2c(i2c, &as3722_regmap_config);
- if (IS_ERR(as3722->regmap)) {
- ret = PTR_ERR(as3722->regmap);
- dev_err(&i2c->dev, "regmap_init failed with err: %d\n", ret);
- return ret;
- }
-
- irq_flags = pdata->irq_type;
- irq_flags |= IRQF_ONESHOT;
- ret = regmap_add_irq_chip(as3722->regmap, as3722->chip_irq,
- irq_flags, pdata->irq_base, &as3722_irq_chip,
- &as3722->irq_data);
- if (ret < 0) {
- dev_err(as3722->dev,
- "irq allocation failed for as3722 failed\n");
- return ret;
- }
-
- ret = as3722_init(as3722, pdata, i2c->irq);
- if (ret < 0)
- return ret;
-
- ret = mfd_add_devices(&i2c->dev, -1, as3722_devs,
- ARRAY_SIZE(as3722_devs), NULL,
- pdata->irq_base,
- regmap_irq_get_domain(as3722->irq_data));
- if (ret) {
- dev_err(as3722->dev, "add mfd devices failed with err: %d\n",
- ret);
- return ret;
- }
-
- dev_info(as3722->dev,
- "AS3722 core driver %s initialized successfully\n",
- AS3722_DRIVER_VERSION);
-
- return 0;
-}
-
-static int as3722_i2c_remove(struct i2c_client *i2c)
-{
- struct as3722 *as3722 = i2c_get_clientdata(i2c);
-
- mfd_remove_devices(as3722->dev);
- regmap_del_irq_chip(as3722->chip_irq, as3722->irq_data);
-
- return 0;
-}
-
-static const struct i2c_device_id as3722_i2c_id[] = {
- {"as3722", 0},
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, as3722_i2c_id);
-
-static struct i2c_driver as3722_i2c_driver = {
- .driver = {
- .name = "as3722",
- .owner = THIS_MODULE,
- },
- .probe = as3722_i2c_probe,
- .remove = as3722_i2c_remove,
- .id_table = as3722_i2c_id,
-};
-
-static int __init as3722_i2c_init(void)
-{
- return i2c_add_driver(&as3722_i2c_driver);
-}
-
-subsys_initcall(as3722_i2c_init);
-
-static void __exit as3722_i2c_exit(void)
-{
- i2c_del_driver(&as3722_i2c_driver);
-}
-
-module_exit(as3722_i2c_exit);
-
-MODULE_DESCRIPTION("I2C support for AS3722 PMICs");
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
diff --git a/drivers/mfd/as3722-test.c b/drivers/mfd/as3722-test.c
deleted file mode 100644
index f5332baadeba..000000000000
--- a/drivers/mfd/as3722-test.c
+++ /dev/null
@@ -1,430 +0,0 @@
-/*
- * as3722-test.c - testing the AS3722 driver
- *
- * Copyright (C) 2013 ams AG
- *
- * Author: Florian Lobmaier <florian.lobmaier@ams.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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include <linux/err.h>
-#include <linux/bug.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/list.h>
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
-#include <linux/regulator/consumer.h>
-#include <linux/mfd/as3722-reg.h>
-#include <linux/mfd/as3722-plat.h>
-
-struct dyn_file_data {
- struct regulator *reg;
- int is_open;
- int is_status_read;
-};
-
-struct regulator_list {
- struct list_head list;
- struct dentry *fs_entry;
- struct dyn_file_data *fdata;
-};
-
-static struct dentry *debug_dir;
-static struct dentry *create_reg;
-
-static struct regulator_list regulators;
-
-static ssize_t dyn_regulator_read(struct file *file,
- char __user *user_buf,
- size_t size, loff_t *ppos)
-{
- int i;
- char buf[100];
- ssize_t buf_size;
- struct dyn_file_data *fdata = file->private_data;
- struct regulator *reg = fdata->reg;
-
- int enabled = regulator_is_enabled(reg);
- int voltage = regulator_get_voltage(reg);
- int current_limit = regulator_get_current_limit(reg);
- int mode = regulator_get_mode(reg);
-
- if (fdata->is_status_read)
- return 0;
-
- buf_size = min(size, (sizeof(buf) - 1));
-
- i = sprintf(buf,
- "enabled: %d voltage: %duV current_limit: %d%s mode=%s\n",
- enabled, voltage, current_limit,
- current_limit < 1 ? "" : "uA",
- mode < 0 ? "<unknown>" : mode ==
- REGULATOR_MODE_FAST ? "fast" : "normal");
-
- if (copy_to_user(user_buf, buf, i))
- return -EFAULT;
-
- fdata->is_status_read = 1;
-
- return i;
-}
-
-static ssize_t dyn_regulator_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- int ret;
- char buf[80];
- char *pos;
- ssize_t buf_size;
- struct dyn_file_data *fdata = file->private_data;
- struct regulator *reg = fdata->reg;
-
- buf_size = min(count, (sizeof(buf) - 1));
- if (copy_from_user(buf, user_buf, buf_size))
- return -EFAULT;
- buf[buf_size] = 0;
-
- if (strcmp(buf, "enable") == 0) {
-
- /* calls to enable and disable needs to be balanced!
- check if the regulator is already enabled */
-
- if (regulator_is_enabled(reg) > 0) {
- printk(KERN_ERR "%s: regulator enabled already\n",
- __func__);
- return buf_size;
- }
-
- ret = regulator_enable(reg);
- if (ret < 0) {
- printk(KERN_ERR "%s: enable %d\n", __func__, ret);
- return -EINVAL;
- }
- return buf_size;
-
- } else if (strcmp(buf, "disable") == 0) {
-
- if (regulator_is_enabled(reg) == 0) {
- printk(KERN_ERR "%s: regulator disabled already\n",
- __func__);
- return buf_size;
- }
-
- ret = regulator_disable(reg);
- if (ret < 0) {
- printk(KERN_ERR "%s: disable %d\n", __func__, ret);
- return -EINVAL;
- }
- return buf_size;
-
- } else if (strstr(buf, "set_voltage") != NULL) {
-
- /* we expect "set_voltage uV_min uV_max" */
-
- int uV_min = -1;
- int uV_max = -1;
-
- pos = strchr(buf, ' ');
- if (!pos) {
- printk(KERN_ERR "%s: set_voltage error parse uV_min\n",
- __func__);
- return -EINVAL;
- }
- pos++;
- uV_min = simple_strtol(pos, 0, 10);
- pos = strchr(pos, ' ');
- if (!pos) {
- printk(KERN_ERR "%s: set_voltage error parse uV_max\n",
- __func__);
- return -EINVAL;
- }
- pos++;
- uV_max = simple_strtol(pos, 0, 10);
- if (uV_min < 0 || uV_max < 0) {
- printk(KERN_ERR
- "%s: error voltage: uV_min=%d uV_max=%d\n",
- __func__, uV_min, uV_max);
- return -EINVAL;
- }
- ret = regulator_set_voltage(reg, uV_min, uV_max);
- if (ret < 0) {
- printk(KERN_ERR
- "%s: set_voltage: uV_min=%d uV_max=%d ret=%d\n",
- __func__, uV_min, uV_max, ret);
- return -EINVAL;
- }
-
- return buf_size;
-
- } else if (strstr(buf, "set_current") != NULL) {
-
- /* we expect "set_current uA_min uA_max" */
-
- int uA_min = -1;
- int uA_max = -1;
-
- pos = strchr(buf, ' ');
- if (!pos) {
- printk(KERN_ERR "%s: set_current error parse uA_min\n",
- __func__);
- return -EINVAL;
- }
- pos++;
- uA_min = simple_strtol(pos, 0, 10);
- pos = strchr(pos, ' ');
- if (!pos) {
- printk(KERN_ERR "%s: set_current error parse uA_max\n",
- __func__);
- return -EINVAL;
- }
- pos++;
- uA_max = simple_strtol(pos, 0, 10);
- if (uA_min < 0 || uA_max < 0) {
- printk(KERN_ERR
- "%s: error current: uA_min=%d uA_max=%d\n",
- __func__, uA_min, uA_max);
- return -EINVAL;
- }
-
- ret = regulator_set_current_limit(reg, uA_min, uA_max);
- if (ret < 0) {
- printk(KERN_ERR
- "%s: set_current: uA_min=%d uA_max=%d ret=%d\n",
- __func__, uA_min, uA_max, ret);
- return -EINVAL;
- }
-
- return buf_size;
- } else if (strstr(buf, "set_mode") != NULL) {
-
- int mode;
-
- pos = strchr(buf, ' ');
- if (!pos) {
- printk(KERN_ERR "%s: set_mode command parse\n",
- __func__);
- return -EINVAL;
- }
- pos++;
- if (strcmp(pos, "normal") == 0) {
- mode = REGULATOR_MODE_NORMAL;
- } else if (strcmp(pos, "fast") == 0) {
- mode = REGULATOR_MODE_FAST;
- } else {
- printk(KERN_ERR "%s: mode %s not supported!\n",
- __func__, pos);
- return -EINVAL;
- }
-
- ret = regulator_set_mode(reg, mode);
- if (ret < 0) {
- printk(KERN_ERR "%s: set_mode: %s ret=%d\n",
- __func__, pos, ret);
- return -EINVAL;
- }
-
- return buf_size;
- }
-
- printk(KERN_ERR "%s: command invalid: %s\n", __func__, buf);
-
- return buf_size;
-}
-
-static int dyn_regulator_open(struct inode *inode, struct file *file)
-{
- struct dyn_file_data *fdata = inode->i_private;
-
- if (fdata->is_open)
- return -EBUSY;
-
- fdata->is_open = 1;
- fdata->is_status_read = 0;
-
- file->private_data = fdata;
-
- return 0;
-}
-
-static int dyn_regulator_release(struct inode *inode, struct file *file)
-{
- struct dyn_file_data *fdata = file->private_data;
-
- fdata->is_open = 0;
-
- return 0;
-}
-
-static const struct file_operations dyn_regulator_fsops = {
- .open = dyn_regulator_open,
- .read = dyn_regulator_read,
- .write = dyn_regulator_write,
- .release = dyn_regulator_release,
-};
-
-static int create_regulator_open(struct inode *inode, struct file *file)
-{
- file->private_data = inode->i_private;
- return 0;
-}
-
-static ssize_t create_regulator_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- int ret;
- char buf[32];
- ssize_t buf_size;
- struct regulator *reg;
- struct dyn_file_data *fdata;
- struct regulator_list *reg_list_entry;
- struct dentry *fs_entry;
-
- /* get userspace string and assure termination */
- buf_size = min(count, (sizeof(buf) - 1));
- if (copy_from_user(buf, user_buf, buf_size))
- return -EFAULT;
-
- buf[buf_size] = 0;
-
- reg = regulator_get(NULL, buf);
- if (IS_ERR(reg)) {
- printk(KERN_ERR "%s: there is no supply voltage: %s\n",
- __func__, buf);
- return -EINVAL;
- }
-
- fdata = kmalloc(sizeof(struct dyn_file_data), GFP_KERNEL);
- if (!fdata) {
- printk(KERN_ERR "%s: cannot kmalloc fdata\n", __func__);
- return -ENOMEM;
- }
-
- fdata->reg = reg;
- fdata->is_open = 0;
- fdata->is_status_read = 0;
-
- fs_entry = debugfs_create_file(buf, (S_IWUGO | S_IRUGO), debug_dir,
- fdata, &dyn_regulator_fsops);
- if (!fs_entry) {
- printk(KERN_ERR "%s: cannot create fs_entry for %s\n",
- __func__, buf);
- ret = -EINVAL;
- goto exit_no_fs_entry;
- }
-
- reg_list_entry = kmalloc(sizeof(struct regulator_list), GFP_KERNEL);
- if (!reg_list_entry) {
- printk(KERN_ERR "%s: cannot kmalloc reg_list_entry for %s\n",
- __func__, buf);
- ret = -ENOMEM;
- goto exit_no_reg_list_entry;
- }
-
- reg_list_entry->fs_entry = fs_entry;
-
- /* we save the fdata for free(), how to get it from dentry? */
- reg_list_entry->fdata = fdata;
-
- list_add(&(reg_list_entry->list), &(regulators.list));
-
- return buf_size;
-
-exit_no_reg_list_entry:
- debugfs_remove(fs_entry);
-exit_no_fs_entry:
- kfree(fdata);
- return ret;
-}
-
-static const struct file_operations create_regulator_fsops = {
- .open = create_regulator_open,
- .write = create_regulator_write,
-};
-
-static int as3722_test_probe(void)
-{
- INIT_LIST_HEAD(&regulators.list);
-
- debug_dir = debugfs_create_dir("as3722", NULL);
- if (!debug_dir) {
- printk(KERN_ERR "%s: cannot create debugfs\n", __func__);
- goto exit_no_debugfs;
- }
-
- create_reg = debugfs_create_file("create_regulator", S_IWUGO, debug_dir,
- NULL, &create_regulator_fsops);
- if (!create_reg) {
- printk(KERN_ERR "%s: cannot create create_reg\n", __func__);
- goto exit_no_create_reg;
- }
-
- return 0;
-
-exit_no_create_reg:
- debugfs_remove(debug_dir);
- debug_dir = NULL;
-exit_no_debugfs:
- return -EINVAL;
-}
-
-static int as3722_test_remove(void)
-{
- struct list_head *pos, *q;
- struct regulator_list *reg_list_entry;
- struct dyn_file_data *fdata;
-
- list_for_each_safe(pos, q, &regulators.list) {
- reg_list_entry = list_entry(pos, struct regulator_list, list);
- list_del(pos);
- fdata = reg_list_entry->fdata;
- regulator_put(fdata->reg);
- debugfs_remove(reg_list_entry->fs_entry);
- kfree(fdata);
- kfree(reg_list_entry);
- }
-
- if (create_reg)
- debugfs_remove(create_reg);
-
- if (debug_dir)
- debugfs_remove(debug_dir);
-
- return 0;
-}
-
-static int __init as3722_test_init(void)
-{
- as3722_test_probe();
- return 0;
-}
-
-static void __exit as3722_test_exit(void)
-{
- as3722_test_remove();
-}
-
-module_init(as3722_test_init);
-module_exit(as3722_test_exit);
-
-MODULE_DESCRIPTION("AS3722 PMIC testing");
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
-