drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / dca / dca-sysfs.c
CommitLineData
e2fc4d19
MS
1/*
2 * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59
16 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called COPYING.
20 */
21
7589670f
SN
22#include <linux/kernel.h>
23#include <linux/spinlock.h>
24#include <linux/device.h>
25#include <linux/idr.h>
26#include <linux/kdev_t.h>
27#include <linux/err.h>
28#include <linux/dca.h>
5a0e3ad6 29#include <linux/gfp.h>
3382416d 30#include <linux/export.h>
7589670f
SN
31
32static struct class *dca_class;
33static struct idr dca_idr;
34static spinlock_t dca_idr_lock;
35
36int dca_sysfs_add_req(struct dca_provider *dca, struct device *dev, int slot)
37{
765cdb6c 38 struct device *cd;
7f1b358a 39 static int req_count;
7589670f 40
a9b12619
GKH
41 cd = device_create(dca_class, dca->cd, MKDEV(0, slot + 1), NULL,
42 "requester%d", req_count++);
7589670f
SN
43 if (IS_ERR(cd))
44 return PTR_ERR(cd);
45 return 0;
46}
47
48void dca_sysfs_remove_req(struct dca_provider *dca, int slot)
49{
765cdb6c 50 device_destroy(dca_class, MKDEV(0, slot + 1));
7589670f
SN
51}
52
53int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
54{
765cdb6c 55 struct device *cd;
615f2e5c 56 int ret;
7589670f 57
615f2e5c 58 idr_preload(GFP_KERNEL);
7589670f 59 spin_lock(&dca_idr_lock);
615f2e5c
TH
60
61 ret = idr_alloc(&dca_idr, dca, 0, 0, GFP_NOWAIT);
62 if (ret >= 0)
63 dca->id = ret;
64
7589670f 65 spin_unlock(&dca_idr_lock);
615f2e5c
TH
66 idr_preload_end();
67 if (ret < 0)
68 return ret;
7589670f 69
a9b12619 70 cd = device_create(dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id);
7589670f
SN
71 if (IS_ERR(cd)) {
72 spin_lock(&dca_idr_lock);
73 idr_remove(&dca_idr, dca->id);
74 spin_unlock(&dca_idr_lock);
75 return PTR_ERR(cd);
76 }
77 dca->cd = cd;
78 return 0;
79}
80
81void dca_sysfs_remove_provider(struct dca_provider *dca)
82{
765cdb6c 83 device_unregister(dca->cd);
7589670f
SN
84 dca->cd = NULL;
85 spin_lock(&dca_idr_lock);
86 idr_remove(&dca_idr, dca->id);
87 spin_unlock(&dca_idr_lock);
88}
89
90int __init dca_sysfs_init(void)
91{
92 idr_init(&dca_idr);
93 spin_lock_init(&dca_idr_lock);
94
95 dca_class = class_create(THIS_MODULE, "dca");
96 if (IS_ERR(dca_class)) {
97 idr_destroy(&dca_idr);
98 return PTR_ERR(dca_class);
99 }
100 return 0;
101}
102
103void __exit dca_sysfs_exit(void)
104{
105 class_destroy(dca_class);
106 idr_destroy(&dca_idr);
107}
108