summaryrefslogtreecommitdiff
path: root/drivers/soc/fsl/qixis_ctrl.c
blob: f5da93c107c4f4fd12dc89c5733a35efa632668e (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * Freescale QIXIS system controller driver.
 *
 * Copyright 2015 Freescale Semiconductor, Inc.
 *
 * 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.
 */

#include <linux/device.h>
#include <linux/err.h>
#include <linux/fsl/qixis_ctrl.h>
#include <linux/io.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/regmap.h>

#ifdef CONFIG_PPC
#include <asm/machdep.h>
#endif

static struct regmap *qixis_regmap;

/* QIXIS Power Management Control*/
#define QIXIS_PWR_CTL2_PWR	0x80
static void fsl_qixis_power_off(void)
{
	u32 val;

	local_irq_disable();

	regmap_read(qixis_regmap, offsetof(struct fsl_qixis_regs, pwr_ctrl2),
		    &val);
	val |= QIXIS_PWR_CTL2_PWR;
	regmap_write(qixis_regmap, offsetof(struct fsl_qixis_regs, pwr_ctrl2),
		     val);

	while (1)
		;
}

static void fsl_qixis_pm_init(void)
{
#if defined(CONFIG_PPC)
	ppc_md.power_off = fsl_qixis_power_off;
	ppc_md.halt = fsl_qixis_power_off;
#elif defined(CONFIG_ARM)
	pm_power_off = fsl_qixis_power_off;
#endif
}

static void fsl_qixis_pm_release(void)
{
#if defined(CONFIG_PPC)
	ppc_md.power_off = NULL;
	ppc_md.halt = NULL;
#elif defined(CONFIG_ARM)
	pm_power_off = NULL;
#endif
}

static struct regmap_config qixis_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
};

static int fsl_qixis_probe(struct platform_device *pdev)
{
	static struct fsl_qixis_regs __iomem *qixis;
	struct resource *res;
	u32 qver;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	qixis = devm_ioremap_resource(&pdev->dev, res);
	if (IS_ERR(qixis)) {
		pr_err("%s: Could not map qixis registers\n", __func__);
		return PTR_ERR(qixis);
	}

	qixis_regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, qixis,
						 &qixis_regmap_config);

	fsl_qixis_pm_init();

	regmap_read(qixis_regmap, offsetof(struct fsl_qixis_regs, qixis_ver),
		    &qver);

	pr_info("Freescale QIXIS Version: 0x%08x\n", qver);

	return 0;
}

static int fsl_qixis_remove(struct platform_device *pdev)
{
	fsl_qixis_pm_release();

	return 0;
}

static const struct of_device_id fsl_qixis_table[] = {
	{ .compatible = "fsl,fpga-qixis", },
	{ .compatible = "fsl,ls1021aqds-fpga", },
	{},
};

static struct platform_driver fsl_qixis_driver = {
	.driver = {
		.name = "fsl-qixis",
		.owner = THIS_MODULE,
		.of_match_table = fsl_qixis_table,
	},
	.probe = fsl_qixis_probe,
	.remove = fsl_qixis_remove,
};
module_platform_driver(fsl_qixis_driver);

static int fsl_qixis_i2c_probe(struct i2c_client *client,
			       const struct i2c_device_id *id)
{
	u32 qver;

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return -EOPNOTSUPP;

	qixis_regmap = regmap_init_i2c(client, &qixis_regmap_config);

	fsl_qixis_pm_init();

	regmap_read(qixis_regmap, offsetof(struct fsl_qixis_regs, qixis_ver),
		    &qver);

	pr_info("Freescale QIXIS Version: 0x%08x\n", qver);

	return 0;
}

static int fsl_qixis_i2c_remove(struct i2c_client *client)
{
	fsl_qixis_pm_release();

	return 0;
}

static const struct i2c_device_id fsl_qixis_id[] = {
	{ "fpga-qixis-i2c", 0 },
	{ "bsc9132qds-fpga", 0 },
	{}
};
MODULE_DEVICE_TABLE(i2c, fsl_qixis_id);

static struct i2c_driver fsl_qixis_i2c_driver = {
	.driver = {
		.name	= "fpga-qixis-i2c",
		.owner	= THIS_MODULE,
	},
	.probe		= fsl_qixis_i2c_probe,
	.remove		= fsl_qixis_i2c_remove,
	.id_table	= fsl_qixis_id,
};
module_i2c_driver(fsl_qixis_i2c_driver);

MODULE_AUTHOR("Wang Dongsheng <dongsheng.wang@freescale.com>");
MODULE_DESCRIPTION("Freescale QIXIS system controller driver");
MODULE_LICENSE("GPL v2");