Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2008-2009, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /* Qualcomm PMIC Multi-Purpose Pin Configurations */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/debugfs.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
| 22 | #include <mach/mpp.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 23 | #include <mach/proc_comm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 24 | |
| 25 | int mpp_config_digital_out(unsigned mpp, unsigned config) |
| 26 | { |
| 27 | int err; |
| 28 | err = msm_proc_comm(PCOM_PM_MPP_CONFIG, &mpp, &config); |
| 29 | if (err) |
| 30 | pr_err("%s: msm_proc_comm(PCOM_PM_MPP_CONFIG) failed\n", |
| 31 | __func__); |
| 32 | return err; |
| 33 | } |
| 34 | EXPORT_SYMBOL(mpp_config_digital_out); |
| 35 | |
| 36 | int mpp_config_digital_in(unsigned mpp, unsigned config) |
| 37 | { |
| 38 | int err; |
| 39 | err = msm_proc_comm(PCOM_PM_MPP_CONFIG_DIGITAL_INPUT, &mpp, &config); |
| 40 | if (err) |
| 41 | pr_err("%s: msm_proc_comm(PCOM_PM_MPP_CONFIG) failed\n", |
| 42 | __func__); |
| 43 | return err; |
| 44 | } |
| 45 | EXPORT_SYMBOL(mpp_config_digital_in); |
| 46 | |
| 47 | #if defined(CONFIG_DEBUG_FS) |
| 48 | static int test_result; |
| 49 | |
| 50 | static int mpp_debug_set(void *data, u64 val) |
| 51 | { |
| 52 | unsigned mpp = (unsigned) data; |
| 53 | |
| 54 | test_result = mpp_config_digital_out(mpp, (unsigned)val); |
| 55 | if (test_result) { |
| 56 | printk(KERN_ERR |
| 57 | "%s: mpp_config_digital_out \ |
| 58 | [mpp(%d) = 0x%x] failed (err=%d)\n", |
| 59 | __func__, mpp, (unsigned)val, test_result); |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int mpp_debug_get(void *data, u64 *val) |
| 65 | { |
| 66 | if (!test_result) |
| 67 | *val = 0; |
| 68 | else |
| 69 | *val = 1; |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | DEFINE_SIMPLE_ATTRIBUTE(mpp_fops, mpp_debug_get, mpp_debug_set, "%llu\n"); |
| 74 | |
| 75 | static int __init mpp_debug_init(void) |
| 76 | { |
| 77 | struct dentry *dent; |
| 78 | int n; |
| 79 | char file_name[16]; |
| 80 | |
| 81 | dent = debugfs_create_dir("mpp", 0); |
| 82 | if (IS_ERR(dent)) |
| 83 | return 0; |
| 84 | |
| 85 | for (n = 0; n < MPPS; n++) { |
| 86 | snprintf(file_name, sizeof(file_name), "mpp%d", n + 1); |
| 87 | debugfs_create_file(file_name, 0644, dent, |
| 88 | (void *)n, &mpp_fops); |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | device_initcall(mpp_debug_init); |
| 95 | #endif |
| 96 | |