aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/devinfo/mt6735/devinfosys.c
blob: a1ea989bbd6e3cc88c6e336296d63aebb2284fa9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) 2015 MediaTek Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * 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.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/cdev.h>
#include <linux/mm.h>
#include <asm/io.h>
#include <linux/uaccess.h>
#include <linux/ioctl.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include "devinfo.h"
#include "mach/mt_devinfo.h"


/**************************************************************************
*  DEV DRIVER SYSFS
**************************************************************************/

static struct platform_driver dev_info = {
	.driver  = {
		.name = "dev_info",
		.bus = &platform_bus_type,
		.owner = THIS_MODULE,
	}
};

static ssize_t devinfo_show(struct device_driver *driver, char *buf)
{
	unsigned int i;
	unsigned int *output = (unsigned int *)buf;

	output[0] = devinfo_get_size();
	for (i = 0; i < output[0]; i++)
		output[i + 1] = get_devinfo_with_index(i);

	return (output[0] + 1) * sizeof(unsigned int);
}

DRIVER_ATTR(dev_info, 0444, devinfo_show, NULL);

static int __init devinfo_init(void)
{
	int ret = 0;

	/* register driver and create sysfs files */
	ret = driver_register(&dev_info.driver);
	if (ret) {
		pr_warn("fail to register devinfo driver\n");
		return -1;
	}

	ret = driver_create_file(&dev_info.driver, &driver_attr_dev_info);
	if (ret) {
		pr_warn("[BOOT INIT] Fail to create devinfo sysfs file\n");
		driver_unregister(&dev_info.driver);
		return -1;
	}

	return 0;
}
module_init(devinfo_init);