xref: /openbmc/linux/drivers/media/dvb-frontends/sp2.c (revision 9a25d410bbc84074578ff2fb3c39aa768c7d5555)
1868736adSOlli Salonen /*
2868736adSOlli Salonen  * CIMaX SP2/SP2HF (Atmel T90FJR) CI driver
3868736adSOlli Salonen  *
4868736adSOlli Salonen  * Copyright (C) 2014 Olli Salonen <olli.salonen@iki.fi>
5868736adSOlli Salonen  *
6868736adSOlli Salonen  * Heavily based on CIMax2(R) SP2 driver in conjunction with NetUp Dual
7868736adSOlli Salonen  * DVB-S2 CI card (cimax2) with following copyrights:
8868736adSOlli Salonen  *
9868736adSOlli Salonen  *  Copyright (C) 2009 NetUP Inc.
10868736adSOlli Salonen  *  Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
11868736adSOlli Salonen  *  Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
12868736adSOlli Salonen  *
13868736adSOlli Salonen  *    This program is free software; you can redistribute it and/or modify
14868736adSOlli Salonen  *    it under the terms of the GNU General Public License as published by
15868736adSOlli Salonen  *    the Free Software Foundation; either version 2 of the License, or
16868736adSOlli Salonen  *    (at your option) any later version.
17868736adSOlli Salonen  *
18868736adSOlli Salonen  *    This program is distributed in the hope that it will be useful,
19868736adSOlli Salonen  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
20868736adSOlli Salonen  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21868736adSOlli Salonen  *    GNU General Public License for more details.
22868736adSOlli Salonen  */
23868736adSOlli Salonen 
24868736adSOlli Salonen #include "sp2_priv.h"
25868736adSOlli Salonen 
26868736adSOlli Salonen static int sp2_read_i2c(struct sp2 *s, u8 reg, u8 *buf, int len)
27868736adSOlli Salonen {
28868736adSOlli Salonen 	int ret;
29868736adSOlli Salonen 	struct i2c_client *client = s->client;
30868736adSOlli Salonen 	struct i2c_adapter *adap = client->adapter;
31868736adSOlli Salonen 	struct i2c_msg msg[] = {
32868736adSOlli Salonen 		{
33868736adSOlli Salonen 			.addr = client->addr,
34868736adSOlli Salonen 			.flags = 0,
35868736adSOlli Salonen 			.buf = &reg,
36868736adSOlli Salonen 			.len = 1
37868736adSOlli Salonen 		}, {
38868736adSOlli Salonen 			.addr = client->addr,
39868736adSOlli Salonen 			.flags	= I2C_M_RD,
40868736adSOlli Salonen 			.buf = buf,
41868736adSOlli Salonen 			.len = len
42868736adSOlli Salonen 		}
43868736adSOlli Salonen 	};
44868736adSOlli Salonen 
45868736adSOlli Salonen 	ret = i2c_transfer(adap, msg, 2);
46868736adSOlli Salonen 
47868736adSOlli Salonen 	if (ret != 2) {
48868736adSOlli Salonen 		dev_err(&client->dev, "i2c read error, reg = 0x%02x, status = %d\n",
49868736adSOlli Salonen 				reg, ret);
50868736adSOlli Salonen 		if (ret < 0)
51868736adSOlli Salonen 			return ret;
52868736adSOlli Salonen 		else
53868736adSOlli Salonen 			return -EIO;
54868736adSOlli Salonen 	}
55868736adSOlli Salonen 
56868736adSOlli Salonen 	dev_dbg(&s->client->dev, "addr=0x%04x, reg = 0x%02x, data = %02x\n",
57868736adSOlli Salonen 				client->addr, reg, buf[0]);
58868736adSOlli Salonen 
59868736adSOlli Salonen 	return 0;
60868736adSOlli Salonen }
61868736adSOlli Salonen 
62868736adSOlli Salonen static int sp2_write_i2c(struct sp2 *s, u8 reg, u8 *buf, int len)
63868736adSOlli Salonen {
64868736adSOlli Salonen 	int ret;
65868736adSOlli Salonen 	u8 buffer[35];
66868736adSOlli Salonen 	struct i2c_client *client = s->client;
67868736adSOlli Salonen 	struct i2c_adapter *adap = client->adapter;
68868736adSOlli Salonen 	struct i2c_msg msg = {
69868736adSOlli Salonen 		.addr = client->addr,
70868736adSOlli Salonen 		.flags = 0,
71868736adSOlli Salonen 		.buf = &buffer[0],
72868736adSOlli Salonen 		.len = len + 1
73868736adSOlli Salonen 	};
74868736adSOlli Salonen 
75868736adSOlli Salonen 	if ((len + 1) > sizeof(buffer)) {
76868736adSOlli Salonen 		dev_err(&client->dev, "i2c wr reg=%02x: len=%d is too big!\n",
77868736adSOlli Salonen 				reg, len);
78868736adSOlli Salonen 		return -EINVAL;
79868736adSOlli Salonen 	}
80868736adSOlli Salonen 
81868736adSOlli Salonen 	buffer[0] = reg;
82868736adSOlli Salonen 	memcpy(&buffer[1], buf, len);
83868736adSOlli Salonen 
84868736adSOlli Salonen 	ret = i2c_transfer(adap, &msg, 1);
85868736adSOlli Salonen 
86868736adSOlli Salonen 	if (ret != 1) {
87868736adSOlli Salonen 		dev_err(&client->dev, "i2c write error, reg = 0x%02x, status = %d\n",
88868736adSOlli Salonen 				reg, ret);
89868736adSOlli Salonen 		if (ret < 0)
90868736adSOlli Salonen 			return ret;
91868736adSOlli Salonen 		else
92868736adSOlli Salonen 			return -EIO;
93868736adSOlli Salonen 	}
94868736adSOlli Salonen 
95868736adSOlli Salonen 	return 0;
96868736adSOlli Salonen }
97868736adSOlli Salonen 
98868736adSOlli Salonen static int sp2_ci_op_cam(struct dvb_ca_en50221 *en50221, int slot, u8 acs,
99868736adSOlli Salonen 			u8 read, int addr, u8 data)
100868736adSOlli Salonen {
101868736adSOlli Salonen 	struct sp2 *s = en50221->data;
102868736adSOlli Salonen 	u8 store;
103868736adSOlli Salonen 	int mem, ret;
104868736adSOlli Salonen 	int (*ci_op_cam)(void*, u8, int, u8, int*) = s->ci_control;
105868736adSOlli Salonen 
106868736adSOlli Salonen 	dev_dbg(&s->client->dev, "slot=%d, acs=0x%02x, addr=0x%04x, data = 0x%02x",
107868736adSOlli Salonen 			slot, acs, addr, data);
108868736adSOlli Salonen 
109868736adSOlli Salonen 	if (slot != 0)
110868736adSOlli Salonen 		return -EINVAL;
111868736adSOlli Salonen 
112868736adSOlli Salonen 	/*
113868736adSOlli Salonen 	 * change module access type between IO space and attribute memory
114868736adSOlli Salonen 	 * when needed
115868736adSOlli Salonen 	 */
116868736adSOlli Salonen 	if (s->module_access_type != acs) {
117868736adSOlli Salonen 		ret = sp2_read_i2c(s, 0x00, &store, 1);
118868736adSOlli Salonen 
119868736adSOlli Salonen 		if (ret)
120868736adSOlli Salonen 			return ret;
121868736adSOlli Salonen 
122868736adSOlli Salonen 		store &= ~(SP2_MOD_CTL_ACS1 | SP2_MOD_CTL_ACS0);
123868736adSOlli Salonen 		store |= acs;
124868736adSOlli Salonen 
125868736adSOlli Salonen 		ret = sp2_write_i2c(s, 0x00, &store, 1);
126868736adSOlli Salonen 		if (ret)
127868736adSOlli Salonen 			return ret;
128868736adSOlli Salonen 	}
129868736adSOlli Salonen 
130868736adSOlli Salonen 	s->module_access_type = acs;
131868736adSOlli Salonen 
132868736adSOlli Salonen 	/* implementation of ci_op_cam is device specific */
133868736adSOlli Salonen 	if (ci_op_cam) {
134868736adSOlli Salonen 		ret = ci_op_cam(s->priv, read, addr, data, &mem);
135868736adSOlli Salonen 	} else {
136868736adSOlli Salonen 		dev_err(&s->client->dev, "callback not defined");
137868736adSOlli Salonen 		return -EINVAL;
138868736adSOlli Salonen 	}
139868736adSOlli Salonen 
140868736adSOlli Salonen 	if (ret)
141868736adSOlli Salonen 		return ret;
142868736adSOlli Salonen 
143868736adSOlli Salonen 	if (read) {
144868736adSOlli Salonen 		dev_dbg(&s->client->dev, "cam read, addr=0x%04x, data = 0x%04x",
145868736adSOlli Salonen 				addr, mem);
146868736adSOlli Salonen 		return mem;
147868736adSOlli Salonen 	} else {
148868736adSOlli Salonen 		return 0;
149868736adSOlli Salonen 	}
150868736adSOlli Salonen }
151868736adSOlli Salonen 
152868736adSOlli Salonen int sp2_ci_read_attribute_mem(struct dvb_ca_en50221 *en50221,
153868736adSOlli Salonen 				int slot, int addr)
154868736adSOlli Salonen {
155868736adSOlli Salonen 	return sp2_ci_op_cam(en50221, slot, SP2_CI_ATTR_ACS,
156868736adSOlli Salonen 			SP2_CI_RD, addr, 0);
157868736adSOlli Salonen }
158868736adSOlli Salonen 
159868736adSOlli Salonen int sp2_ci_write_attribute_mem(struct dvb_ca_en50221 *en50221,
160868736adSOlli Salonen 				int slot, int addr, u8 data)
161868736adSOlli Salonen {
162868736adSOlli Salonen 	return sp2_ci_op_cam(en50221, slot, SP2_CI_ATTR_ACS,
163868736adSOlli Salonen 			SP2_CI_WR, addr, data);
164868736adSOlli Salonen }
165868736adSOlli Salonen 
166868736adSOlli Salonen int sp2_ci_read_cam_control(struct dvb_ca_en50221 *en50221,
167868736adSOlli Salonen 				int slot, u8 addr)
168868736adSOlli Salonen {
169868736adSOlli Salonen 	return sp2_ci_op_cam(en50221, slot, SP2_CI_IO_ACS,
170868736adSOlli Salonen 			SP2_CI_RD, addr, 0);
171868736adSOlli Salonen }
172868736adSOlli Salonen 
173868736adSOlli Salonen int sp2_ci_write_cam_control(struct dvb_ca_en50221 *en50221,
174868736adSOlli Salonen 				int slot, u8 addr, u8 data)
175868736adSOlli Salonen {
176868736adSOlli Salonen 	return sp2_ci_op_cam(en50221, slot, SP2_CI_IO_ACS,
177868736adSOlli Salonen 			SP2_CI_WR, addr, data);
178868736adSOlli Salonen }
179868736adSOlli Salonen 
180868736adSOlli Salonen int sp2_ci_slot_reset(struct dvb_ca_en50221 *en50221, int slot)
181868736adSOlli Salonen {
182868736adSOlli Salonen 	struct sp2 *s = en50221->data;
183868736adSOlli Salonen 	u8 buf;
184868736adSOlli Salonen 	int ret;
185868736adSOlli Salonen 
186868736adSOlli Salonen 	dev_dbg(&s->client->dev, "slot: %d\n", slot);
187868736adSOlli Salonen 
188868736adSOlli Salonen 	if (slot != 0)
189868736adSOlli Salonen 		return -EINVAL;
190868736adSOlli Salonen 
191868736adSOlli Salonen 	/* RST on */
192868736adSOlli Salonen 	buf = SP2_MOD_CTL_RST;
193868736adSOlli Salonen 	ret = sp2_write_i2c(s, 0x00, &buf, 1);
194868736adSOlli Salonen 
195868736adSOlli Salonen 	if (ret)
196868736adSOlli Salonen 		return ret;
197868736adSOlli Salonen 
198868736adSOlli Salonen 	usleep_range(500, 600);
199868736adSOlli Salonen 
200868736adSOlli Salonen 	/* RST off */
201868736adSOlli Salonen 	buf = 0x00;
202868736adSOlli Salonen 	ret = sp2_write_i2c(s, 0x00, &buf, 1);
203868736adSOlli Salonen 
204868736adSOlli Salonen 	if (ret)
205868736adSOlli Salonen 		return ret;
206868736adSOlli Salonen 
207868736adSOlli Salonen 	msleep(1000);
208868736adSOlli Salonen 
209868736adSOlli Salonen 	return 0;
210868736adSOlli Salonen }
211868736adSOlli Salonen 
212868736adSOlli Salonen int sp2_ci_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)
213868736adSOlli Salonen {
214868736adSOlli Salonen 	struct sp2 *s = en50221->data;
215868736adSOlli Salonen 
216868736adSOlli Salonen 	dev_dbg(&s->client->dev, "slot:%d\n", slot);
217868736adSOlli Salonen 
218868736adSOlli Salonen 	/* not implemented */
219868736adSOlli Salonen 	return 0;
220868736adSOlli Salonen }
221868736adSOlli Salonen 
222868736adSOlli Salonen int sp2_ci_slot_ts_enable(struct dvb_ca_en50221 *en50221, int slot)
223868736adSOlli Salonen {
224868736adSOlli Salonen 	struct sp2 *s = en50221->data;
225868736adSOlli Salonen 	u8 buf;
226868736adSOlli Salonen 
227868736adSOlli Salonen 	dev_dbg(&s->client->dev, "slot:%d\n", slot);
228868736adSOlli Salonen 
229868736adSOlli Salonen 	if (slot != 0)
230868736adSOlli Salonen 		return -EINVAL;
231868736adSOlli Salonen 
232868736adSOlli Salonen 	sp2_read_i2c(s, 0x00, &buf, 1);
233868736adSOlli Salonen 
234868736adSOlli Salonen 	/* disable bypass and enable TS */
235868736adSOlli Salonen 	buf |= (SP2_MOD_CTL_TSOEN | SP2_MOD_CTL_TSIEN);
236868736adSOlli Salonen 	return sp2_write_i2c(s, 0, &buf, 1);
237868736adSOlli Salonen }
238868736adSOlli Salonen 
239868736adSOlli Salonen int sp2_ci_poll_slot_status(struct dvb_ca_en50221 *en50221,
240868736adSOlli Salonen 				int slot, int open)
241868736adSOlli Salonen {
242868736adSOlli Salonen 	struct sp2 *s = en50221->data;
243868736adSOlli Salonen 	u8 buf[2];
244868736adSOlli Salonen 	int ret;
245868736adSOlli Salonen 
246868736adSOlli Salonen 	dev_dbg(&s->client->dev, "slot:%d open:%d\n", slot, open);
247868736adSOlli Salonen 
248868736adSOlli Salonen 	/*
249868736adSOlli Salonen 	 * CAM module INSERT/REMOVE processing. Slow operation because of i2c
250868736adSOlli Salonen 	 * transfers. Throttle read to one per sec.
251868736adSOlli Salonen 	 */
252868736adSOlli Salonen 	if (time_after(jiffies, s->next_status_checked_time)) {
253868736adSOlli Salonen 		ret = sp2_read_i2c(s, 0x00, buf, 1);
254868736adSOlli Salonen 		s->next_status_checked_time = jiffies +	msecs_to_jiffies(1000);
255868736adSOlli Salonen 
256868736adSOlli Salonen 		if (ret)
257868736adSOlli Salonen 			return 0;
258868736adSOlli Salonen 
259868736adSOlli Salonen 		if (buf[0] & SP2_MOD_CTL_DET)
260868736adSOlli Salonen 			s->status = DVB_CA_EN50221_POLL_CAM_PRESENT |
261868736adSOlli Salonen 					DVB_CA_EN50221_POLL_CAM_READY;
262868736adSOlli Salonen 		else
263868736adSOlli Salonen 			s->status = 0;
264868736adSOlli Salonen 	}
265868736adSOlli Salonen 
266868736adSOlli Salonen 	return s->status;
267868736adSOlli Salonen }
268868736adSOlli Salonen 
269868736adSOlli Salonen int sp2_init(struct sp2 *s)
270868736adSOlli Salonen {
271868736adSOlli Salonen 	int ret = 0;
272868736adSOlli Salonen 	u8 buf;
273868736adSOlli Salonen 	u8 cimax_init[34] = {
274868736adSOlli Salonen 		0x00, /* module A control*/
275868736adSOlli Salonen 		0x00, /* auto select mask high A */
276868736adSOlli Salonen 		0x00, /* auto select mask low A */
277868736adSOlli Salonen 		0x00, /* auto select pattern high A */
278868736adSOlli Salonen 		0x00, /* auto select pattern low A */
279868736adSOlli Salonen 		0x44, /* memory access time A, 600 ns */
280868736adSOlli Salonen 		0x00, /* invert input A */
281868736adSOlli Salonen 		0x00, /* RFU */
282868736adSOlli Salonen 		0x00, /* RFU */
283868736adSOlli Salonen 		0x00, /* module B control*/
284868736adSOlli Salonen 		0x00, /* auto select mask high B */
285868736adSOlli Salonen 		0x00, /* auto select mask low B */
286868736adSOlli Salonen 		0x00, /* auto select pattern high B */
287868736adSOlli Salonen 		0x00, /* auto select pattern low B */
288868736adSOlli Salonen 		0x44, /* memory access time B, 600 ns */
289868736adSOlli Salonen 		0x00, /* invert input B */
290868736adSOlli Salonen 		0x00, /* RFU */
291868736adSOlli Salonen 		0x00, /* RFU */
292868736adSOlli Salonen 		0x00, /* auto select mask high Ext */
293868736adSOlli Salonen 		0x00, /* auto select mask low Ext */
294868736adSOlli Salonen 		0x00, /* auto select pattern high Ext */
295868736adSOlli Salonen 		0x00, /* auto select pattern low Ext */
296868736adSOlli Salonen 		0x00, /* RFU */
297868736adSOlli Salonen 		0x02, /* destination - module A */
298868736adSOlli Salonen 		0x01, /* power control reg, VCC power on */
299868736adSOlli Salonen 		0x00, /* RFU */
300868736adSOlli Salonen 		0x00, /* int status read only */
301868736adSOlli Salonen 		0x00, /* Interrupt Mask Register */
302868736adSOlli Salonen 		0x05, /* EXTINT=active-high, INT=push-pull */
303868736adSOlli Salonen 		0x00, /* USCG1 */
304868736adSOlli Salonen 		0x04, /* ack active low */
305868736adSOlli Salonen 		0x00, /* LOCK = 0 */
306868736adSOlli Salonen 		0x22, /* unknown */
307868736adSOlli Salonen 		0x00, /* synchronization? */
308868736adSOlli Salonen 	};
309868736adSOlli Salonen 
310868736adSOlli Salonen 	dev_dbg(&s->client->dev, "\n");
311868736adSOlli Salonen 
312868736adSOlli Salonen 	s->ca.owner = THIS_MODULE;
313868736adSOlli Salonen 	s->ca.read_attribute_mem = sp2_ci_read_attribute_mem;
314868736adSOlli Salonen 	s->ca.write_attribute_mem = sp2_ci_write_attribute_mem;
315868736adSOlli Salonen 	s->ca.read_cam_control = sp2_ci_read_cam_control;
316868736adSOlli Salonen 	s->ca.write_cam_control = sp2_ci_write_cam_control;
317868736adSOlli Salonen 	s->ca.slot_reset = sp2_ci_slot_reset;
318868736adSOlli Salonen 	s->ca.slot_shutdown = sp2_ci_slot_shutdown;
319868736adSOlli Salonen 	s->ca.slot_ts_enable = sp2_ci_slot_ts_enable;
320868736adSOlli Salonen 	s->ca.poll_slot_status = sp2_ci_poll_slot_status;
321868736adSOlli Salonen 	s->ca.data = s;
322868736adSOlli Salonen 	s->module_access_type = 0;
323868736adSOlli Salonen 
324868736adSOlli Salonen 	/* initialize all regs */
325868736adSOlli Salonen 	ret = sp2_write_i2c(s, 0x00, &cimax_init[0], 34);
326868736adSOlli Salonen 	if (ret)
327868736adSOlli Salonen 		goto err;
328868736adSOlli Salonen 
329868736adSOlli Salonen 	/* lock registers */
330868736adSOlli Salonen 	buf = 1;
331868736adSOlli Salonen 	ret = sp2_write_i2c(s, 0x1f, &buf, 1);
332868736adSOlli Salonen 	if (ret)
333868736adSOlli Salonen 		goto err;
334868736adSOlli Salonen 
335868736adSOlli Salonen 	/* power on slots */
336868736adSOlli Salonen 	ret = sp2_write_i2c(s, 0x18, &buf, 1);
337868736adSOlli Salonen 	if (ret)
338868736adSOlli Salonen 		goto err;
339868736adSOlli Salonen 
340868736adSOlli Salonen 	ret = dvb_ca_en50221_init(s->dvb_adap, &s->ca, 0, 1);
341868736adSOlli Salonen 	if (ret)
342868736adSOlli Salonen 		goto err;
343868736adSOlli Salonen 
344868736adSOlli Salonen 	return 0;
345868736adSOlli Salonen 
346868736adSOlli Salonen err:
347868736adSOlli Salonen 	dev_dbg(&s->client->dev, "init failed=%d\n", ret);
348868736adSOlli Salonen 	return ret;
349868736adSOlli Salonen }
350868736adSOlli Salonen 
351868736adSOlli Salonen int sp2_exit(struct i2c_client *client)
352868736adSOlli Salonen {
353868736adSOlli Salonen 	struct sp2 *s;
354868736adSOlli Salonen 
355868736adSOlli Salonen 	dev_dbg(&client->dev, "\n");
356868736adSOlli Salonen 
357868736adSOlli Salonen 	if (client == NULL)
358868736adSOlli Salonen 		return 0;
359868736adSOlli Salonen 
360868736adSOlli Salonen 	s = i2c_get_clientdata(client);
361868736adSOlli Salonen 	if (s == NULL)
362868736adSOlli Salonen 		return 0;
363868736adSOlli Salonen 
364868736adSOlli Salonen 	if (s->ca.data == NULL)
365868736adSOlli Salonen 		return 0;
366868736adSOlli Salonen 
367868736adSOlli Salonen 	dvb_ca_en50221_release(&s->ca);
368868736adSOlli Salonen 
369868736adSOlli Salonen 	return 0;
370868736adSOlli Salonen }
371868736adSOlli Salonen 
372868736adSOlli Salonen static int sp2_probe(struct i2c_client *client,
373868736adSOlli Salonen 		const struct i2c_device_id *id)
374868736adSOlli Salonen {
375868736adSOlli Salonen 	struct sp2_config *cfg = client->dev.platform_data;
376868736adSOlli Salonen 	struct sp2 *s;
377868736adSOlli Salonen 	int ret;
378868736adSOlli Salonen 
379868736adSOlli Salonen 	dev_dbg(&client->dev, "\n");
380868736adSOlli Salonen 
381868736adSOlli Salonen 	s = kzalloc(sizeof(struct sp2), GFP_KERNEL);
382868736adSOlli Salonen 	if (!s) {
383868736adSOlli Salonen 		ret = -ENOMEM;
384868736adSOlli Salonen 		dev_err(&client->dev, "kzalloc() failed\n");
385868736adSOlli Salonen 		goto err;
386868736adSOlli Salonen 	}
387868736adSOlli Salonen 
388868736adSOlli Salonen 	s->client = client;
389868736adSOlli Salonen 	s->dvb_adap = cfg->dvb_adap;
390868736adSOlli Salonen 	s->priv = cfg->priv;
391868736adSOlli Salonen 	s->ci_control = cfg->ci_control;
392868736adSOlli Salonen 
393868736adSOlli Salonen 	i2c_set_clientdata(client, s);
394868736adSOlli Salonen 
395868736adSOlli Salonen 	ret = sp2_init(s);
396868736adSOlli Salonen 	if (ret)
397868736adSOlli Salonen 		goto err;
398868736adSOlli Salonen 
399868736adSOlli Salonen 	dev_info(&s->client->dev, "CIMaX SP2 successfully attached\n");
400868736adSOlli Salonen 	return 0;
401868736adSOlli Salonen err:
402868736adSOlli Salonen 	dev_dbg(&client->dev, "init failed=%d\n", ret);
403868736adSOlli Salonen 	kfree(s);
404868736adSOlli Salonen 
405868736adSOlli Salonen 	return ret;
406868736adSOlli Salonen }
407868736adSOlli Salonen 
408868736adSOlli Salonen static int sp2_remove(struct i2c_client *client)
409868736adSOlli Salonen {
410*9a25d410SOlli Salonen 	struct sp2 *s = i2c_get_clientdata(client);
411868736adSOlli Salonen 
412868736adSOlli Salonen 	dev_dbg(&client->dev, "\n");
413868736adSOlli Salonen 
414868736adSOlli Salonen 	sp2_exit(client);
415868736adSOlli Salonen 	if (s != NULL)
416868736adSOlli Salonen 		kfree(s);
417868736adSOlli Salonen 
418868736adSOlli Salonen 	return 0;
419868736adSOlli Salonen }
420868736adSOlli Salonen 
421868736adSOlli Salonen static const struct i2c_device_id sp2_id[] = {
422868736adSOlli Salonen 	{"sp2", 0},
423868736adSOlli Salonen 	{}
424868736adSOlli Salonen };
425868736adSOlli Salonen MODULE_DEVICE_TABLE(i2c, sp2_id);
426868736adSOlli Salonen 
427868736adSOlli Salonen static struct i2c_driver sp2_driver = {
428868736adSOlli Salonen 	.driver = {
429868736adSOlli Salonen 		.owner	= THIS_MODULE,
430868736adSOlli Salonen 		.name	= "sp2",
431868736adSOlli Salonen 	},
432868736adSOlli Salonen 	.probe		= sp2_probe,
433868736adSOlli Salonen 	.remove		= sp2_remove,
434868736adSOlli Salonen 	.id_table	= sp2_id,
435868736adSOlli Salonen };
436868736adSOlli Salonen 
437868736adSOlli Salonen module_i2c_driver(sp2_driver);
438868736adSOlli Salonen 
439868736adSOlli Salonen MODULE_DESCRIPTION("CIMaX SP2/HF CI driver");
440868736adSOlli Salonen MODULE_AUTHOR("Olli Salonen <olli.salonen@iki.fi>");
441868736adSOlli Salonen MODULE_LICENSE("GPL");
442