summaryrefslogtreecommitdiff
path: root/arch/arm/mach-mx5/mx53_smd_rfkill.c
blob: f0f95a839381b10c1875d81cdb692dd24d808492 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*!
 * @file mxc_bt_rfkill.c
 *
 * @brief This driver is implement a rfkill control interface of bluetooth
 * chip on i.MX serial boards. Register the power regulator function and
 * reset function in platform data.
 */

#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/rfkill.h>
#include <mach/hardware.h>
#include <mach/mxc_rfkill.h>

static int mxc_bt_set_block(void *rfkdata, bool blocked)
{
	struct mxc_bt_rfkill_platform_data *data = rfkdata;
	int ret;

	pr_info("rfkill: BT RF going to : %s\n", blocked ? "off" : "on");
	if (!blocked)
		ret = data->power_change(1);
	else
		ret = data->power_change(0);

	return ret;
}

static const struct rfkill_ops mxc_bt_rfkill_ops = {
	.set_block = mxc_bt_set_block,
};

static int mxc_bt_rfkill_probe(struct platform_device *dev)
{
	int rc;
	struct rfkill *rfk;

	struct mxc_bt_rfkill_platform_data *data = dev->dev.platform_data;

	if (data->power_change == NULL) {
		rc = -EINVAL;
		dev_err(&dev->dev, "no power_change function\n");
		goto error_check_func;
	}

	rfk = rfkill_alloc("mxc-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH,
			   &mxc_bt_rfkill_ops, data);

	if (!rfk) {
		rc = -ENOMEM;
		goto error_rfk_alloc;
	}

	rfkill_set_led_trigger_name(rfk, "mxc_bt");

	rc = rfkill_register(rfk);
	if (rc)
		goto error_rfkill;

	platform_set_drvdata(dev, rfk);
	printk(KERN_INFO "mxc_bt_rfkill driver success loaded\n");
	return 0;

error_rfkill:
	rfkill_destroy(rfk);
error_rfk_alloc:
error_check_func:
	return rc;
}

static int __devexit mxc_bt_rfkill_remove(struct platform_device *dev)
{
	struct mxc_bt_rfkill_platform_data *data = dev->dev.platform_data;
	struct rfkill *rfk = platform_get_drvdata(dev);

	platform_set_drvdata(dev, NULL);

	if (rfk) {
		rfkill_unregister(rfk);
		rfkill_destroy(rfk);
	}

	data->power_change(0);

	return 0;
}

static struct platform_driver mxc_bt_rfkill_drv = {
	.driver = {
		.name = "mxc_bt_rfkill",
	},

	.probe	= mxc_bt_rfkill_probe,
	.remove = __devexit_p(mxc_bt_rfkill_remove),
};

static int __init mxc_bt_rfkill_init(void)
{
	return platform_driver_register(&mxc_bt_rfkill_drv);
}

module_init(mxc_bt_rfkill_init);

static void __exit mxc_bt_rfkill_exit(void)
{
	platform_driver_unregister(&mxc_bt_rfkill_drv);
}

module_exit(mxc_bt_rfkill_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("RFKill control interface of BT on MX53 SMD");