xref: /linux/drivers/i2c/busses/i2c-sun6i-p2wi.c (revision 3e833490fae55633f6adc03a5e6172d47c01f3e4)
1*3e833490SBoris BREZILLON /*
2*3e833490SBoris BREZILLON  * P2WI (Push-Pull Two Wire Interface) bus driver.
3*3e833490SBoris BREZILLON  *
4*3e833490SBoris BREZILLON  * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
5*3e833490SBoris BREZILLON  *
6*3e833490SBoris BREZILLON  * This file is licensed under the terms of the GNU General Public License
7*3e833490SBoris BREZILLON  * version 2.  This program is licensed "as is" without any warranty of any
8*3e833490SBoris BREZILLON  * kind, whether express or implied.
9*3e833490SBoris BREZILLON  *
10*3e833490SBoris BREZILLON  * The P2WI controller looks like an SMBus controller which only supports byte
11*3e833490SBoris BREZILLON  * data transfers. But, it differs from standard SMBus protocol on several
12*3e833490SBoris BREZILLON  * aspects:
13*3e833490SBoris BREZILLON  * - it supports only one slave device, and thus drop the address field
14*3e833490SBoris BREZILLON  * - it adds a parity bit every 8bits of data
15*3e833490SBoris BREZILLON  * - only one read access is required to read a byte (instead of a write
16*3e833490SBoris BREZILLON  *   followed by a read access in standard SMBus protocol)
17*3e833490SBoris BREZILLON  * - there's no Ack bit after each byte transfer
18*3e833490SBoris BREZILLON  *
19*3e833490SBoris BREZILLON  * This means this bus cannot be used to interface with standard SMBus
20*3e833490SBoris BREZILLON  * devices (the only known device to support this interface is the AXP221
21*3e833490SBoris BREZILLON  * PMIC).
22*3e833490SBoris BREZILLON  *
23*3e833490SBoris BREZILLON  */
24*3e833490SBoris BREZILLON #include <linux/clk.h>
25*3e833490SBoris BREZILLON #include <linux/module.h>
26*3e833490SBoris BREZILLON #include <linux/i2c.h>
27*3e833490SBoris BREZILLON #include <linux/io.h>
28*3e833490SBoris BREZILLON #include <linux/interrupt.h>
29*3e833490SBoris BREZILLON #include <linux/module.h>
30*3e833490SBoris BREZILLON #include <linux/of.h>
31*3e833490SBoris BREZILLON #include <linux/platform_device.h>
32*3e833490SBoris BREZILLON #include <linux/reset.h>
33*3e833490SBoris BREZILLON 
34*3e833490SBoris BREZILLON 
35*3e833490SBoris BREZILLON /* P2WI registers */
36*3e833490SBoris BREZILLON #define P2WI_CTRL		0x0
37*3e833490SBoris BREZILLON #define P2WI_CCR		0x4
38*3e833490SBoris BREZILLON #define P2WI_INTE		0x8
39*3e833490SBoris BREZILLON #define P2WI_INTS		0xc
40*3e833490SBoris BREZILLON #define P2WI_DADDR0		0x10
41*3e833490SBoris BREZILLON #define P2WI_DADDR1		0x14
42*3e833490SBoris BREZILLON #define P2WI_DLEN		0x18
43*3e833490SBoris BREZILLON #define P2WI_DATA0		0x1c
44*3e833490SBoris BREZILLON #define P2WI_DATA1		0x20
45*3e833490SBoris BREZILLON #define P2WI_LCR		0x24
46*3e833490SBoris BREZILLON #define P2WI_PMCR		0x28
47*3e833490SBoris BREZILLON 
48*3e833490SBoris BREZILLON /* CTRL fields */
49*3e833490SBoris BREZILLON #define P2WI_CTRL_START_TRANS		BIT(7)
50*3e833490SBoris BREZILLON #define P2WI_CTRL_ABORT_TRANS		BIT(6)
51*3e833490SBoris BREZILLON #define P2WI_CTRL_GLOBAL_INT_ENB	BIT(1)
52*3e833490SBoris BREZILLON #define P2WI_CTRL_SOFT_RST		BIT(0)
53*3e833490SBoris BREZILLON 
54*3e833490SBoris BREZILLON /* CLK CTRL fields */
55*3e833490SBoris BREZILLON #define P2WI_CCR_SDA_OUT_DELAY(v)	(((v) & 0x7) << 8)
56*3e833490SBoris BREZILLON #define P2WI_CCR_MAX_CLK_DIV		0xff
57*3e833490SBoris BREZILLON #define P2WI_CCR_CLK_DIV(v)		((v) & P2WI_CCR_MAX_CLK_DIV)
58*3e833490SBoris BREZILLON 
59*3e833490SBoris BREZILLON /* STATUS fields */
60*3e833490SBoris BREZILLON #define P2WI_INTS_TRANS_ERR_ID(v)	(((v) >> 8) & 0xff)
61*3e833490SBoris BREZILLON #define P2WI_INTS_LOAD_BSY		BIT(2)
62*3e833490SBoris BREZILLON #define P2WI_INTS_TRANS_ERR		BIT(1)
63*3e833490SBoris BREZILLON #define P2WI_INTS_TRANS_OVER		BIT(0)
64*3e833490SBoris BREZILLON 
65*3e833490SBoris BREZILLON /* DATA LENGTH fields*/
66*3e833490SBoris BREZILLON #define P2WI_DLEN_READ			BIT(4)
67*3e833490SBoris BREZILLON #define P2WI_DLEN_DATA_LENGTH(v)	((v - 1) & 0x7)
68*3e833490SBoris BREZILLON 
69*3e833490SBoris BREZILLON /* LINE CTRL fields*/
70*3e833490SBoris BREZILLON #define P2WI_LCR_SCL_STATE		BIT(5)
71*3e833490SBoris BREZILLON #define P2WI_LCR_SDA_STATE		BIT(4)
72*3e833490SBoris BREZILLON #define P2WI_LCR_SCL_CTL		BIT(3)
73*3e833490SBoris BREZILLON #define P2WI_LCR_SCL_CTL_EN		BIT(2)
74*3e833490SBoris BREZILLON #define P2WI_LCR_SDA_CTL		BIT(1)
75*3e833490SBoris BREZILLON #define P2WI_LCR_SDA_CTL_EN		BIT(0)
76*3e833490SBoris BREZILLON 
77*3e833490SBoris BREZILLON /* PMU MODE CTRL fields */
78*3e833490SBoris BREZILLON #define P2WI_PMCR_PMU_INIT_SEND		BIT(31)
79*3e833490SBoris BREZILLON #define P2WI_PMCR_PMU_INIT_DATA(v)	(((v) & 0xff) << 16)
80*3e833490SBoris BREZILLON #define P2WI_PMCR_PMU_MODE_REG(v)	(((v) & 0xff) << 8)
81*3e833490SBoris BREZILLON #define P2WI_PMCR_PMU_DEV_ADDR(v)	((v) & 0xff)
82*3e833490SBoris BREZILLON 
83*3e833490SBoris BREZILLON #define P2WI_MAX_FREQ			6000000
84*3e833490SBoris BREZILLON 
85*3e833490SBoris BREZILLON struct p2wi {
86*3e833490SBoris BREZILLON 	struct i2c_adapter adapter;
87*3e833490SBoris BREZILLON 	struct completion complete;
88*3e833490SBoris BREZILLON 	unsigned int status;
89*3e833490SBoris BREZILLON 	void __iomem *regs;
90*3e833490SBoris BREZILLON 	struct clk *clk;
91*3e833490SBoris BREZILLON 	struct reset_control *rstc;
92*3e833490SBoris BREZILLON 	int slave_addr;
93*3e833490SBoris BREZILLON };
94*3e833490SBoris BREZILLON 
95*3e833490SBoris BREZILLON static irqreturn_t p2wi_interrupt(int irq, void *dev_id)
96*3e833490SBoris BREZILLON {
97*3e833490SBoris BREZILLON 	struct p2wi *p2wi = dev_id;
98*3e833490SBoris BREZILLON 	unsigned long status;
99*3e833490SBoris BREZILLON 
100*3e833490SBoris BREZILLON 	status = readl(p2wi->regs + P2WI_INTS);
101*3e833490SBoris BREZILLON 	p2wi->status = status;
102*3e833490SBoris BREZILLON 
103*3e833490SBoris BREZILLON 	/* Clear interrupts */
104*3e833490SBoris BREZILLON 	status &= (P2WI_INTS_LOAD_BSY | P2WI_INTS_TRANS_ERR |
105*3e833490SBoris BREZILLON 		   P2WI_INTS_TRANS_OVER);
106*3e833490SBoris BREZILLON 	writel(status, p2wi->regs + P2WI_INTS);
107*3e833490SBoris BREZILLON 
108*3e833490SBoris BREZILLON 	complete(&p2wi->complete);
109*3e833490SBoris BREZILLON 
110*3e833490SBoris BREZILLON 	return IRQ_HANDLED;
111*3e833490SBoris BREZILLON }
112*3e833490SBoris BREZILLON 
113*3e833490SBoris BREZILLON static u32 p2wi_functionality(struct i2c_adapter *adap)
114*3e833490SBoris BREZILLON {
115*3e833490SBoris BREZILLON 	return I2C_FUNC_SMBUS_BYTE_DATA;
116*3e833490SBoris BREZILLON }
117*3e833490SBoris BREZILLON 
118*3e833490SBoris BREZILLON static int p2wi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
119*3e833490SBoris BREZILLON 			   unsigned short flags, char read_write,
120*3e833490SBoris BREZILLON 			   u8 command, int size, union i2c_smbus_data *data)
121*3e833490SBoris BREZILLON {
122*3e833490SBoris BREZILLON 	struct p2wi *p2wi = i2c_get_adapdata(adap);
123*3e833490SBoris BREZILLON 	unsigned long dlen = P2WI_DLEN_DATA_LENGTH(1);
124*3e833490SBoris BREZILLON 
125*3e833490SBoris BREZILLON 	if (p2wi->slave_addr >= 0 && addr != p2wi->slave_addr) {
126*3e833490SBoris BREZILLON 		dev_err(&adap->dev, "invalid P2WI address\n");
127*3e833490SBoris BREZILLON 		return -EINVAL;
128*3e833490SBoris BREZILLON 	}
129*3e833490SBoris BREZILLON 
130*3e833490SBoris BREZILLON 	if (!data)
131*3e833490SBoris BREZILLON 		return -EINVAL;
132*3e833490SBoris BREZILLON 
133*3e833490SBoris BREZILLON 	writel(command, p2wi->regs + P2WI_DADDR0);
134*3e833490SBoris BREZILLON 
135*3e833490SBoris BREZILLON 	if (read_write == I2C_SMBUS_READ)
136*3e833490SBoris BREZILLON 		dlen |= P2WI_DLEN_READ;
137*3e833490SBoris BREZILLON 	else
138*3e833490SBoris BREZILLON 		writel(data->byte, p2wi->regs + P2WI_DATA0);
139*3e833490SBoris BREZILLON 
140*3e833490SBoris BREZILLON 	writel(dlen, p2wi->regs + P2WI_DLEN);
141*3e833490SBoris BREZILLON 
142*3e833490SBoris BREZILLON 	if (readl(p2wi->regs + P2WI_CTRL) & P2WI_CTRL_START_TRANS) {
143*3e833490SBoris BREZILLON 		dev_err(&adap->dev, "P2WI bus busy\n");
144*3e833490SBoris BREZILLON 		return -EBUSY;
145*3e833490SBoris BREZILLON 	}
146*3e833490SBoris BREZILLON 
147*3e833490SBoris BREZILLON 	reinit_completion(&p2wi->complete);
148*3e833490SBoris BREZILLON 
149*3e833490SBoris BREZILLON 	writel(P2WI_INTS_LOAD_BSY | P2WI_INTS_TRANS_ERR | P2WI_INTS_TRANS_OVER,
150*3e833490SBoris BREZILLON 	       p2wi->regs + P2WI_INTE);
151*3e833490SBoris BREZILLON 
152*3e833490SBoris BREZILLON 	writel(P2WI_CTRL_START_TRANS | P2WI_CTRL_GLOBAL_INT_ENB,
153*3e833490SBoris BREZILLON 	       p2wi->regs + P2WI_CTRL);
154*3e833490SBoris BREZILLON 
155*3e833490SBoris BREZILLON 	wait_for_completion(&p2wi->complete);
156*3e833490SBoris BREZILLON 
157*3e833490SBoris BREZILLON 	if (p2wi->status & P2WI_INTS_LOAD_BSY) {
158*3e833490SBoris BREZILLON 		dev_err(&adap->dev, "P2WI bus busy\n");
159*3e833490SBoris BREZILLON 		return -EBUSY;
160*3e833490SBoris BREZILLON 	}
161*3e833490SBoris BREZILLON 
162*3e833490SBoris BREZILLON 	if (p2wi->status & P2WI_INTS_TRANS_ERR) {
163*3e833490SBoris BREZILLON 		dev_err(&adap->dev, "P2WI bus xfer error\n");
164*3e833490SBoris BREZILLON 		return -ENXIO;
165*3e833490SBoris BREZILLON 	}
166*3e833490SBoris BREZILLON 
167*3e833490SBoris BREZILLON 	if (read_write == I2C_SMBUS_READ)
168*3e833490SBoris BREZILLON 		data->byte = readl(p2wi->regs + P2WI_DATA0);
169*3e833490SBoris BREZILLON 
170*3e833490SBoris BREZILLON 	return 0;
171*3e833490SBoris BREZILLON }
172*3e833490SBoris BREZILLON 
173*3e833490SBoris BREZILLON static const struct i2c_algorithm p2wi_algo = {
174*3e833490SBoris BREZILLON 	.smbus_xfer = p2wi_smbus_xfer,
175*3e833490SBoris BREZILLON 	.functionality = p2wi_functionality,
176*3e833490SBoris BREZILLON };
177*3e833490SBoris BREZILLON 
178*3e833490SBoris BREZILLON static const struct of_device_id p2wi_of_match_table[] = {
179*3e833490SBoris BREZILLON 	{ .compatible = "allwinner,sun6i-a31-p2wi" },
180*3e833490SBoris BREZILLON 	{}
181*3e833490SBoris BREZILLON };
182*3e833490SBoris BREZILLON MODULE_DEVICE_TABLE(of, p2wi_of_match_table);
183*3e833490SBoris BREZILLON 
184*3e833490SBoris BREZILLON static int p2wi_probe(struct platform_device *pdev)
185*3e833490SBoris BREZILLON {
186*3e833490SBoris BREZILLON 	struct device *dev = &pdev->dev;
187*3e833490SBoris BREZILLON 	struct device_node *np = dev->of_node;
188*3e833490SBoris BREZILLON 	struct device_node *childnp;
189*3e833490SBoris BREZILLON 	unsigned long parent_clk_freq;
190*3e833490SBoris BREZILLON 	u32 clk_freq = 100000;
191*3e833490SBoris BREZILLON 	struct resource *r;
192*3e833490SBoris BREZILLON 	struct p2wi *p2wi;
193*3e833490SBoris BREZILLON 	u32 slave_addr;
194*3e833490SBoris BREZILLON 	int clk_div;
195*3e833490SBoris BREZILLON 	int irq;
196*3e833490SBoris BREZILLON 	int ret;
197*3e833490SBoris BREZILLON 
198*3e833490SBoris BREZILLON 	of_property_read_u32(np, "clock-frequency", &clk_freq);
199*3e833490SBoris BREZILLON 	if (clk_freq > P2WI_MAX_FREQ) {
200*3e833490SBoris BREZILLON 		dev_err(dev,
201*3e833490SBoris BREZILLON 			"required clock-frequency (%u Hz) is too high (max = 6MHz)",
202*3e833490SBoris BREZILLON 			clk_freq);
203*3e833490SBoris BREZILLON 		return -EINVAL;
204*3e833490SBoris BREZILLON 	}
205*3e833490SBoris BREZILLON 
206*3e833490SBoris BREZILLON 	if (of_get_child_count(np) > 1) {
207*3e833490SBoris BREZILLON 		dev_err(dev, "P2WI only supports one slave device\n");
208*3e833490SBoris BREZILLON 		return -EINVAL;
209*3e833490SBoris BREZILLON 	}
210*3e833490SBoris BREZILLON 
211*3e833490SBoris BREZILLON 	p2wi = devm_kzalloc(dev, sizeof(struct p2wi), GFP_KERNEL);
212*3e833490SBoris BREZILLON 	if (!p2wi)
213*3e833490SBoris BREZILLON 		return -ENOMEM;
214*3e833490SBoris BREZILLON 
215*3e833490SBoris BREZILLON 	p2wi->slave_addr = -1;
216*3e833490SBoris BREZILLON 
217*3e833490SBoris BREZILLON 	/*
218*3e833490SBoris BREZILLON 	 * Authorize a p2wi node without any children to be able to use an
219*3e833490SBoris BREZILLON 	 * i2c-dev from userpace.
220*3e833490SBoris BREZILLON 	 * In this case the slave_addr is set to -1 and won't be checked when
221*3e833490SBoris BREZILLON 	 * launching a P2WI transfer.
222*3e833490SBoris BREZILLON 	 */
223*3e833490SBoris BREZILLON 	childnp = of_get_next_available_child(np, NULL);
224*3e833490SBoris BREZILLON 	if (childnp) {
225*3e833490SBoris BREZILLON 		ret = of_property_read_u32(childnp, "reg", &slave_addr);
226*3e833490SBoris BREZILLON 		if (ret) {
227*3e833490SBoris BREZILLON 			dev_err(dev, "invalid slave address on node %s\n",
228*3e833490SBoris BREZILLON 				childnp->full_name);
229*3e833490SBoris BREZILLON 			return -EINVAL;
230*3e833490SBoris BREZILLON 		}
231*3e833490SBoris BREZILLON 
232*3e833490SBoris BREZILLON 		p2wi->slave_addr = slave_addr;
233*3e833490SBoris BREZILLON 	}
234*3e833490SBoris BREZILLON 
235*3e833490SBoris BREZILLON 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
236*3e833490SBoris BREZILLON 	p2wi->regs = devm_ioremap_resource(dev, r);
237*3e833490SBoris BREZILLON 	if (IS_ERR(p2wi->regs))
238*3e833490SBoris BREZILLON 		return PTR_ERR(p2wi->regs);
239*3e833490SBoris BREZILLON 
240*3e833490SBoris BREZILLON 	snprintf(p2wi->adapter.name, sizeof(p2wi->adapter.name), pdev->name);
241*3e833490SBoris BREZILLON 	irq = platform_get_irq(pdev, 0);
242*3e833490SBoris BREZILLON 	if (irq < 0) {
243*3e833490SBoris BREZILLON 		dev_err(dev, "failed to retrieve irq: %d\n", ret);
244*3e833490SBoris BREZILLON 		return irq;
245*3e833490SBoris BREZILLON 	}
246*3e833490SBoris BREZILLON 
247*3e833490SBoris BREZILLON 	p2wi->clk = devm_clk_get(dev, NULL);
248*3e833490SBoris BREZILLON 	if (IS_ERR(p2wi->clk)) {
249*3e833490SBoris BREZILLON 		ret = PTR_ERR(p2wi->clk);
250*3e833490SBoris BREZILLON 		dev_err(dev, "failed to retrieve clk: %d\n", ret);
251*3e833490SBoris BREZILLON 		return ret;
252*3e833490SBoris BREZILLON 	}
253*3e833490SBoris BREZILLON 
254*3e833490SBoris BREZILLON 	ret = clk_prepare_enable(p2wi->clk);
255*3e833490SBoris BREZILLON 	if (ret) {
256*3e833490SBoris BREZILLON 		dev_err(dev, "failed to enable clk: %d\n", ret);
257*3e833490SBoris BREZILLON 		return ret;
258*3e833490SBoris BREZILLON 	}
259*3e833490SBoris BREZILLON 
260*3e833490SBoris BREZILLON 	parent_clk_freq = clk_get_rate(p2wi->clk);
261*3e833490SBoris BREZILLON 
262*3e833490SBoris BREZILLON 	p2wi->rstc = devm_reset_control_get(dev, NULL);
263*3e833490SBoris BREZILLON 	if (IS_ERR(p2wi->rstc)) {
264*3e833490SBoris BREZILLON 		ret = PTR_ERR(p2wi->rstc);
265*3e833490SBoris BREZILLON 		dev_err(dev, "failed to retrieve reset controller: %d\n", ret);
266*3e833490SBoris BREZILLON 		goto err_clk_disable;
267*3e833490SBoris BREZILLON 	}
268*3e833490SBoris BREZILLON 
269*3e833490SBoris BREZILLON 	ret = reset_control_deassert(p2wi->rstc);
270*3e833490SBoris BREZILLON 	if (ret) {
271*3e833490SBoris BREZILLON 		dev_err(dev, "failed to deassert reset line: %d\n", ret);
272*3e833490SBoris BREZILLON 		goto err_clk_disable;
273*3e833490SBoris BREZILLON 	}
274*3e833490SBoris BREZILLON 
275*3e833490SBoris BREZILLON 	init_completion(&p2wi->complete);
276*3e833490SBoris BREZILLON 	p2wi->adapter.dev.parent = dev;
277*3e833490SBoris BREZILLON 	p2wi->adapter.algo = &p2wi_algo;
278*3e833490SBoris BREZILLON 	p2wi->adapter.owner = THIS_MODULE;
279*3e833490SBoris BREZILLON 	p2wi->adapter.dev.of_node = pdev->dev.of_node;
280*3e833490SBoris BREZILLON 	platform_set_drvdata(pdev, p2wi);
281*3e833490SBoris BREZILLON 	i2c_set_adapdata(&p2wi->adapter, p2wi);
282*3e833490SBoris BREZILLON 
283*3e833490SBoris BREZILLON 	ret = devm_request_irq(dev, irq, p2wi_interrupt, 0, pdev->name, p2wi);
284*3e833490SBoris BREZILLON 	if (ret) {
285*3e833490SBoris BREZILLON 		dev_err(dev, "can't register interrupt handler irq%d: %d\n",
286*3e833490SBoris BREZILLON 			irq, ret);
287*3e833490SBoris BREZILLON 		goto err_reset_assert;
288*3e833490SBoris BREZILLON 	}
289*3e833490SBoris BREZILLON 
290*3e833490SBoris BREZILLON 	writel(P2WI_CTRL_SOFT_RST, p2wi->regs + P2WI_CTRL);
291*3e833490SBoris BREZILLON 
292*3e833490SBoris BREZILLON 	clk_div = parent_clk_freq / clk_freq;
293*3e833490SBoris BREZILLON 	if (!clk_div) {
294*3e833490SBoris BREZILLON 		dev_warn(dev,
295*3e833490SBoris BREZILLON 			 "clock-frequency is too high, setting it to %lu Hz\n",
296*3e833490SBoris BREZILLON 			 parent_clk_freq);
297*3e833490SBoris BREZILLON 		clk_div = 1;
298*3e833490SBoris BREZILLON 	} else if (clk_div > P2WI_CCR_MAX_CLK_DIV) {
299*3e833490SBoris BREZILLON 		dev_warn(dev,
300*3e833490SBoris BREZILLON 			 "clock-frequency is too low, setting it to %lu Hz\n",
301*3e833490SBoris BREZILLON 			 parent_clk_freq / P2WI_CCR_MAX_CLK_DIV);
302*3e833490SBoris BREZILLON 		clk_div = P2WI_CCR_MAX_CLK_DIV;
303*3e833490SBoris BREZILLON 	}
304*3e833490SBoris BREZILLON 
305*3e833490SBoris BREZILLON 	writel(P2WI_CCR_SDA_OUT_DELAY(1) | P2WI_CCR_CLK_DIV(clk_div),
306*3e833490SBoris BREZILLON 	       p2wi->regs + P2WI_CCR);
307*3e833490SBoris BREZILLON 
308*3e833490SBoris BREZILLON 	ret = i2c_add_adapter(&p2wi->adapter);
309*3e833490SBoris BREZILLON 	if (!ret)
310*3e833490SBoris BREZILLON 		return 0;
311*3e833490SBoris BREZILLON 
312*3e833490SBoris BREZILLON err_reset_assert:
313*3e833490SBoris BREZILLON 	reset_control_assert(p2wi->rstc);
314*3e833490SBoris BREZILLON 
315*3e833490SBoris BREZILLON err_clk_disable:
316*3e833490SBoris BREZILLON 	clk_disable_unprepare(p2wi->clk);
317*3e833490SBoris BREZILLON 
318*3e833490SBoris BREZILLON 	return ret;
319*3e833490SBoris BREZILLON }
320*3e833490SBoris BREZILLON 
321*3e833490SBoris BREZILLON static int p2wi_remove(struct platform_device *dev)
322*3e833490SBoris BREZILLON {
323*3e833490SBoris BREZILLON 	struct p2wi *p2wi = platform_get_drvdata(dev);
324*3e833490SBoris BREZILLON 
325*3e833490SBoris BREZILLON 	reset_control_assert(p2wi->rstc);
326*3e833490SBoris BREZILLON 	clk_disable_unprepare(p2wi->clk);
327*3e833490SBoris BREZILLON 	i2c_del_adapter(&p2wi->adapter);
328*3e833490SBoris BREZILLON 
329*3e833490SBoris BREZILLON 	return 0;
330*3e833490SBoris BREZILLON }
331*3e833490SBoris BREZILLON 
332*3e833490SBoris BREZILLON static struct platform_driver p2wi_driver = {
333*3e833490SBoris BREZILLON 	.probe	= p2wi_probe,
334*3e833490SBoris BREZILLON 	.remove	= p2wi_remove,
335*3e833490SBoris BREZILLON 	.driver	= {
336*3e833490SBoris BREZILLON 		.owner = THIS_MODULE,
337*3e833490SBoris BREZILLON 		.name = "i2c-sunxi-p2wi",
338*3e833490SBoris BREZILLON 		.of_match_table = p2wi_of_match_table,
339*3e833490SBoris BREZILLON 	},
340*3e833490SBoris BREZILLON };
341*3e833490SBoris BREZILLON module_platform_driver(p2wi_driver);
342*3e833490SBoris BREZILLON 
343*3e833490SBoris BREZILLON MODULE_AUTHOR("Boris BREZILLON <boris.brezillon@free-electrons.com>");
344*3e833490SBoris BREZILLON MODULE_DESCRIPTION("Allwinner P2WI driver");
345*3e833490SBoris BREZILLON MODULE_LICENSE("GPL v2");
346