cafe-driver.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * A driver for the CMOS camera controller in the Marvell 88ALP01 "cafe"
  3. * multifunction chip. Currently works with the Omnivision OV7670
  4. * sensor.
  5. *
  6. * The data sheet for this device can be found at:
  7. * http://www.marvell.com/products/pc_connectivity/88alp01/
  8. *
  9. * Copyright 2006-11 One Laptop Per Child Association, Inc.
  10. * Copyright 2006-11 Jonathan Corbet <corbet@lwn.net>
  11. *
  12. * Written by Jonathan Corbet, corbet@lwn.net.
  13. *
  14. * v4l2_device/v4l2_subdev conversion by:
  15. * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
  16. *
  17. * This file may be distributed under the terms of the GNU General
  18. * Public License, version 2.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/pci.h>
  24. #include <linux/i2c.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/slab.h>
  28. #include <linux/videodev2.h>
  29. #include <media/v4l2-device.h>
  30. #include <media/v4l2-chip-ident.h>
  31. #include <linux/device.h>
  32. #include <linux/wait.h>
  33. #include <linux/delay.h>
  34. #include <linux/io.h>
  35. #include "mcam-core.h"
  36. #define CAFE_VERSION 0x000002
  37. /*
  38. * Parameters.
  39. */
  40. MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
  41. MODULE_DESCRIPTION("Marvell 88ALP01 CMOS Camera Controller driver");
  42. MODULE_LICENSE("GPL");
  43. MODULE_SUPPORTED_DEVICE("Video");
  44. struct cafe_camera {
  45. int registered; /* Fully initialized? */
  46. struct mcam_camera mcam;
  47. struct pci_dev *pdev;
  48. wait_queue_head_t smbus_wait; /* Waiting on i2c events */
  49. };
  50. /*
  51. * Most of the camera controller registers are defined in mcam-core.h,
  52. * but the Cafe platform has some additional registers of its own;
  53. * they are described here.
  54. */
  55. /*
  56. * "General purpose register" has a couple of GPIOs used for sensor
  57. * power and reset on OLPC XO 1.0 systems.
  58. */
  59. #define REG_GPR 0xb4
  60. #define GPR_C1EN 0x00000020 /* Pad 1 (power down) enable */
  61. #define GPR_C0EN 0x00000010 /* Pad 0 (reset) enable */
  62. #define GPR_C1 0x00000002 /* Control 1 value */
  63. /*
  64. * Control 0 is wired to reset on OLPC machines. For ov7x sensors,
  65. * it is active low.
  66. */
  67. #define GPR_C0 0x00000001 /* Control 0 value */
  68. /*
  69. * These registers control the SMBUS module for communicating
  70. * with the sensor.
  71. */
  72. #define REG_TWSIC0 0xb8 /* TWSI (smbus) control 0 */
  73. #define TWSIC0_EN 0x00000001 /* TWSI enable */
  74. #define TWSIC0_MODE 0x00000002 /* 1 = 16-bit, 0 = 8-bit */
  75. #define TWSIC0_SID 0x000003fc /* Slave ID */
  76. #define TWSIC0_SID_SHIFT 2
  77. #define TWSIC0_CLKDIV 0x0007fc00 /* Clock divider */
  78. #define TWSIC0_MASKACK 0x00400000 /* Mask ack from sensor */
  79. #define TWSIC0_OVMAGIC 0x00800000 /* Make it work on OV sensors */
  80. #define REG_TWSIC1 0xbc /* TWSI control 1 */
  81. #define TWSIC1_DATA 0x0000ffff /* Data to/from camchip */
  82. #define TWSIC1_ADDR 0x00ff0000 /* Address (register) */
  83. #define TWSIC1_ADDR_SHIFT 16
  84. #define TWSIC1_READ 0x01000000 /* Set for read op */
  85. #define TWSIC1_WSTAT 0x02000000 /* Write status */
  86. #define TWSIC1_RVALID 0x04000000 /* Read data valid */
  87. #define TWSIC1_ERROR 0x08000000 /* Something screwed up */
  88. /*
  89. * Here's the weird global control registers
  90. */
  91. #define REG_GL_CSR 0x3004 /* Control/status register */
  92. #define GCSR_SRS 0x00000001 /* SW Reset set */
  93. #define GCSR_SRC 0x00000002 /* SW Reset clear */
  94. #define GCSR_MRS 0x00000004 /* Master reset set */
  95. #define GCSR_MRC 0x00000008 /* HW Reset clear */
  96. #define GCSR_CCIC_EN 0x00004000 /* CCIC Clock enable */
  97. #define REG_GL_IMASK 0x300c /* Interrupt mask register */
  98. #define GIMSK_CCIC_EN 0x00000004 /* CCIC Interrupt enable */
  99. #define REG_GL_FCR 0x3038 /* GPIO functional control register */
  100. #define GFCR_GPIO_ON 0x08 /* Camera GPIO enabled */
  101. #define REG_GL_GPIOR 0x315c /* GPIO register */
  102. #define GGPIO_OUT 0x80000 /* GPIO output */
  103. #define GGPIO_VAL 0x00008 /* Output pin value */
  104. #define REG_LEN (REG_GL_IMASK + 4)
  105. /*
  106. * Debugging and related.
  107. */
  108. #define cam_err(cam, fmt, arg...) \
  109. dev_err(&(cam)->pdev->dev, fmt, ##arg);
  110. #define cam_warn(cam, fmt, arg...) \
  111. dev_warn(&(cam)->pdev->dev, fmt, ##arg);
  112. /* -------------------------------------------------------------------- */
  113. /*
  114. * The I2C/SMBUS interface to the camera itself starts here. The
  115. * controller handles SMBUS itself, presenting a relatively simple register
  116. * interface; all we have to do is to tell it where to route the data.
  117. */
  118. #define CAFE_SMBUS_TIMEOUT (HZ) /* generous */
  119. static inline struct cafe_camera *to_cam(struct v4l2_device *dev)
  120. {
  121. struct mcam_camera *m = container_of(dev, struct mcam_camera, v4l2_dev);
  122. return container_of(m, struct cafe_camera, mcam);
  123. }
  124. static int cafe_smbus_write_done(struct mcam_camera *mcam)
  125. {
  126. unsigned long flags;
  127. int c1;
  128. /*
  129. * We must delay after the interrupt, or the controller gets confused
  130. * and never does give us good status. Fortunately, we don't do this
  131. * often.
  132. */
  133. udelay(20);
  134. spin_lock_irqsave(&mcam->dev_lock, flags);
  135. c1 = mcam_reg_read(mcam, REG_TWSIC1);
  136. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  137. return (c1 & (TWSIC1_WSTAT|TWSIC1_ERROR)) != TWSIC1_WSTAT;
  138. }
  139. static int cafe_smbus_write_data(struct cafe_camera *cam,
  140. u16 addr, u8 command, u8 value)
  141. {
  142. unsigned int rval;
  143. unsigned long flags;
  144. struct mcam_camera *mcam = &cam->mcam;
  145. spin_lock_irqsave(&mcam->dev_lock, flags);
  146. rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
  147. rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
  148. /*
  149. * Marvell sez set clkdiv to all 1's for now.
  150. */
  151. rval |= TWSIC0_CLKDIV;
  152. mcam_reg_write(mcam, REG_TWSIC0, rval);
  153. (void) mcam_reg_read(mcam, REG_TWSIC1); /* force write */
  154. rval = value | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
  155. mcam_reg_write(mcam, REG_TWSIC1, rval);
  156. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  157. /* Unfortunately, reading TWSIC1 too soon after sending a command
  158. * causes the device to die.
  159. * Use a busy-wait because we often send a large quantity of small
  160. * commands at-once; using msleep() would cause a lot of context
  161. * switches which take longer than 2ms, resulting in a noticeable
  162. * boot-time and capture-start delays.
  163. */
  164. mdelay(2);
  165. /*
  166. * Another sad fact is that sometimes, commands silently complete but
  167. * cafe_smbus_write_done() never becomes aware of this.
  168. * This happens at random and appears to possible occur with any
  169. * command.
  170. * We don't understand why this is. We work around this issue
  171. * with the timeout in the wait below, assuming that all commands
  172. * complete within the timeout.
  173. */
  174. wait_event_timeout(cam->smbus_wait, cafe_smbus_write_done(mcam),
  175. CAFE_SMBUS_TIMEOUT);
  176. spin_lock_irqsave(&mcam->dev_lock, flags);
  177. rval = mcam_reg_read(mcam, REG_TWSIC1);
  178. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  179. if (rval & TWSIC1_WSTAT) {
  180. cam_err(cam, "SMBUS write (%02x/%02x/%02x) timed out\n", addr,
  181. command, value);
  182. return -EIO;
  183. }
  184. if (rval & TWSIC1_ERROR) {
  185. cam_err(cam, "SMBUS write (%02x/%02x/%02x) error\n", addr,
  186. command, value);
  187. return -EIO;
  188. }
  189. return 0;
  190. }
  191. static int cafe_smbus_read_done(struct mcam_camera *mcam)
  192. {
  193. unsigned long flags;
  194. int c1;
  195. /*
  196. * We must delay after the interrupt, or the controller gets confused
  197. * and never does give us good status. Fortunately, we don't do this
  198. * often.
  199. */
  200. udelay(20);
  201. spin_lock_irqsave(&mcam->dev_lock, flags);
  202. c1 = mcam_reg_read(mcam, REG_TWSIC1);
  203. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  204. return c1 & (TWSIC1_RVALID|TWSIC1_ERROR);
  205. }
  206. static int cafe_smbus_read_data(struct cafe_camera *cam,
  207. u16 addr, u8 command, u8 *value)
  208. {
  209. unsigned int rval;
  210. unsigned long flags;
  211. struct mcam_camera *mcam = &cam->mcam;
  212. spin_lock_irqsave(&mcam->dev_lock, flags);
  213. rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
  214. rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
  215. /*
  216. * Marvel sez set clkdiv to all 1's for now.
  217. */
  218. rval |= TWSIC0_CLKDIV;
  219. mcam_reg_write(mcam, REG_TWSIC0, rval);
  220. (void) mcam_reg_read(mcam, REG_TWSIC1); /* force write */
  221. rval = TWSIC1_READ | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
  222. mcam_reg_write(mcam, REG_TWSIC1, rval);
  223. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  224. wait_event_timeout(cam->smbus_wait,
  225. cafe_smbus_read_done(mcam), CAFE_SMBUS_TIMEOUT);
  226. spin_lock_irqsave(&mcam->dev_lock, flags);
  227. rval = mcam_reg_read(mcam, REG_TWSIC1);
  228. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  229. if (rval & TWSIC1_ERROR) {
  230. cam_err(cam, "SMBUS read (%02x/%02x) error\n", addr, command);
  231. return -EIO;
  232. }
  233. if (!(rval & TWSIC1_RVALID)) {
  234. cam_err(cam, "SMBUS read (%02x/%02x) timed out\n", addr,
  235. command);
  236. return -EIO;
  237. }
  238. *value = rval & 0xff;
  239. return 0;
  240. }
  241. /*
  242. * Perform a transfer over SMBUS. This thing is called under
  243. * the i2c bus lock, so we shouldn't race with ourselves...
  244. */
  245. static int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
  246. unsigned short flags, char rw, u8 command,
  247. int size, union i2c_smbus_data *data)
  248. {
  249. struct cafe_camera *cam = i2c_get_adapdata(adapter);
  250. int ret = -EINVAL;
  251. /*
  252. * This interface would appear to only do byte data ops. OK
  253. * it can do word too, but the cam chip has no use for that.
  254. */
  255. if (size != I2C_SMBUS_BYTE_DATA) {
  256. cam_err(cam, "funky xfer size %d\n", size);
  257. return -EINVAL;
  258. }
  259. if (rw == I2C_SMBUS_WRITE)
  260. ret = cafe_smbus_write_data(cam, addr, command, data->byte);
  261. else if (rw == I2C_SMBUS_READ)
  262. ret = cafe_smbus_read_data(cam, addr, command, &data->byte);
  263. return ret;
  264. }
  265. static void cafe_smbus_enable_irq(struct cafe_camera *cam)
  266. {
  267. unsigned long flags;
  268. spin_lock_irqsave(&cam->mcam.dev_lock, flags);
  269. mcam_reg_set_bit(&cam->mcam, REG_IRQMASK, TWSIIRQS);
  270. spin_unlock_irqrestore(&cam->mcam.dev_lock, flags);
  271. }
  272. static u32 cafe_smbus_func(struct i2c_adapter *adapter)
  273. {
  274. return I2C_FUNC_SMBUS_READ_BYTE_DATA |
  275. I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
  276. }
  277. static struct i2c_algorithm cafe_smbus_algo = {
  278. .smbus_xfer = cafe_smbus_xfer,
  279. .functionality = cafe_smbus_func
  280. };
  281. static int cafe_smbus_setup(struct cafe_camera *cam)
  282. {
  283. struct i2c_adapter *adap = &cam->mcam.i2c_adapter;
  284. int ret;
  285. cafe_smbus_enable_irq(cam);
  286. adap->owner = THIS_MODULE;
  287. adap->algo = &cafe_smbus_algo;
  288. strcpy(adap->name, "cafe_ccic");
  289. adap->dev.parent = &cam->pdev->dev;
  290. i2c_set_adapdata(adap, cam);
  291. ret = i2c_add_adapter(adap);
  292. if (ret)
  293. printk(KERN_ERR "Unable to register cafe i2c adapter\n");
  294. return ret;
  295. }
  296. static void cafe_smbus_shutdown(struct cafe_camera *cam)
  297. {
  298. i2c_del_adapter(&cam->mcam.i2c_adapter);
  299. }
  300. /*
  301. * Controller-level stuff
  302. */
  303. static void cafe_ctlr_init(struct mcam_camera *mcam)
  304. {
  305. unsigned long flags;
  306. spin_lock_irqsave(&mcam->dev_lock, flags);
  307. /*
  308. * Added magic to bring up the hardware on the B-Test board
  309. */
  310. mcam_reg_write(mcam, 0x3038, 0x8);
  311. mcam_reg_write(mcam, 0x315c, 0x80008);
  312. /*
  313. * Go through the dance needed to wake the device up.
  314. * Note that these registers are global and shared
  315. * with the NAND and SD devices. Interaction between the
  316. * three still needs to be examined.
  317. */
  318. mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRS|GCSR_MRS); /* Needed? */
  319. mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRC|GCSR_MRC);
  320. mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRC|GCSR_MRS);
  321. /*
  322. * Here we must wait a bit for the controller to come around.
  323. */
  324. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  325. msleep(5);
  326. spin_lock_irqsave(&mcam->dev_lock, flags);
  327. mcam_reg_write(mcam, REG_GL_CSR, GCSR_CCIC_EN|GCSR_SRC|GCSR_MRC);
  328. mcam_reg_set_bit(mcam, REG_GL_IMASK, GIMSK_CCIC_EN);
  329. /*
  330. * Mask all interrupts.
  331. */
  332. mcam_reg_write(mcam, REG_IRQMASK, 0);
  333. spin_unlock_irqrestore(&mcam->dev_lock, flags);
  334. }
  335. static void cafe_ctlr_power_up(struct mcam_camera *mcam)
  336. {
  337. /*
  338. * Part one of the sensor dance: turn the global
  339. * GPIO signal on.
  340. */
  341. mcam_reg_write(mcam, REG_GL_FCR, GFCR_GPIO_ON);
  342. mcam_reg_write(mcam, REG_GL_GPIOR, GGPIO_OUT|GGPIO_VAL);
  343. /*
  344. * Put the sensor into operational mode (assumes OLPC-style
  345. * wiring). Control 0 is reset - set to 1 to operate.
  346. * Control 1 is power down, set to 0 to operate.
  347. */
  348. mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */
  349. mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
  350. }
  351. static void cafe_ctlr_power_down(struct mcam_camera *mcam)
  352. {
  353. mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1);
  354. mcam_reg_write(mcam, REG_GL_FCR, GFCR_GPIO_ON);
  355. mcam_reg_write(mcam, REG_GL_GPIOR, GGPIO_OUT);
  356. }
  357. /*
  358. * The platform interrupt handler.
  359. */
  360. static irqreturn_t cafe_irq(int irq, void *data)
  361. {
  362. struct cafe_camera *cam = data;
  363. struct mcam_camera *mcam = &cam->mcam;
  364. unsigned int irqs, handled;
  365. spin_lock(&mcam->dev_lock);
  366. irqs = mcam_reg_read(mcam, REG_IRQSTAT);
  367. handled = cam->registered && mccic_irq(mcam, irqs);
  368. if (irqs & TWSIIRQS) {
  369. mcam_reg_write(mcam, REG_IRQSTAT, TWSIIRQS);
  370. wake_up(&cam->smbus_wait);
  371. handled = 1;
  372. }
  373. spin_unlock(&mcam->dev_lock);
  374. return IRQ_RETVAL(handled);
  375. }
  376. /* -------------------------------------------------------------------------- */
  377. /*
  378. * PCI interface stuff.
  379. */
  380. static int cafe_pci_probe(struct pci_dev *pdev,
  381. const struct pci_device_id *id)
  382. {
  383. int ret;
  384. struct cafe_camera *cam;
  385. struct mcam_camera *mcam;
  386. /*
  387. * Start putting together one of our big camera structures.
  388. */
  389. ret = -ENOMEM;
  390. cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL);
  391. if (cam == NULL)
  392. goto out;
  393. cam->pdev = pdev;
  394. mcam = &cam->mcam;
  395. mcam->chip_id = V4L2_IDENT_CAFE;
  396. spin_lock_init(&mcam->dev_lock);
  397. init_waitqueue_head(&cam->smbus_wait);
  398. mcam->plat_power_up = cafe_ctlr_power_up;
  399. mcam->plat_power_down = cafe_ctlr_power_down;
  400. mcam->dev = &pdev->dev;
  401. /*
  402. * Set the clock speed for the XO 1; I don't believe this
  403. * driver has ever run anywhere else.
  404. */
  405. mcam->clock_speed = 45;
  406. mcam->use_smbus = 1;
  407. /*
  408. * Get set up on the PCI bus.
  409. */
  410. ret = pci_enable_device(pdev);
  411. if (ret)
  412. goto out_free;
  413. pci_set_master(pdev);
  414. ret = -EIO;
  415. mcam->regs = pci_iomap(pdev, 0, 0);
  416. if (!mcam->regs) {
  417. printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n");
  418. goto out_disable;
  419. }
  420. ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
  421. if (ret)
  422. goto out_iounmap;
  423. /*
  424. * Initialize the controller and leave it powered up. It will
  425. * stay that way until the sensor driver shows up.
  426. */
  427. cafe_ctlr_init(mcam);
  428. cafe_ctlr_power_up(mcam);
  429. /*
  430. * Set up I2C/SMBUS communications. We have to drop the mutex here
  431. * because the sensor could attach in this call chain, leading to
  432. * unsightly deadlocks.
  433. */
  434. ret = cafe_smbus_setup(cam);
  435. if (ret)
  436. goto out_pdown;
  437. ret = mccic_register(mcam);
  438. if (ret == 0) {
  439. cam->registered = 1;
  440. return 0;
  441. }
  442. cafe_smbus_shutdown(cam);
  443. out_pdown:
  444. cafe_ctlr_power_down(mcam);
  445. free_irq(pdev->irq, cam);
  446. out_iounmap:
  447. pci_iounmap(pdev, mcam->regs);
  448. out_disable:
  449. pci_disable_device(pdev);
  450. out_free:
  451. kfree(cam);
  452. out:
  453. return ret;
  454. }
  455. /*
  456. * Shut down an initialized device
  457. */
  458. static void cafe_shutdown(struct cafe_camera *cam)
  459. {
  460. mccic_shutdown(&cam->mcam);
  461. cafe_smbus_shutdown(cam);
  462. free_irq(cam->pdev->irq, cam);
  463. pci_iounmap(cam->pdev, cam->mcam.regs);
  464. }
  465. static void cafe_pci_remove(struct pci_dev *pdev)
  466. {
  467. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  468. struct cafe_camera *cam = to_cam(v4l2_dev);
  469. if (cam == NULL) {
  470. printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev);
  471. return;
  472. }
  473. cafe_shutdown(cam);
  474. kfree(cam);
  475. }
  476. #ifdef CONFIG_PM
  477. /*
  478. * Basic power management.
  479. */
  480. static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  481. {
  482. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  483. struct cafe_camera *cam = to_cam(v4l2_dev);
  484. int ret;
  485. ret = pci_save_state(pdev);
  486. if (ret)
  487. return ret;
  488. mccic_suspend(&cam->mcam);
  489. pci_disable_device(pdev);
  490. return 0;
  491. }
  492. static int cafe_pci_resume(struct pci_dev *pdev)
  493. {
  494. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  495. struct cafe_camera *cam = to_cam(v4l2_dev);
  496. int ret = 0;
  497. pci_restore_state(pdev);
  498. ret = pci_enable_device(pdev);
  499. if (ret) {
  500. cam_warn(cam, "Unable to re-enable device on resume!\n");
  501. return ret;
  502. }
  503. cafe_ctlr_init(&cam->mcam);
  504. return mccic_resume(&cam->mcam);
  505. }
  506. #endif /* CONFIG_PM */
  507. static struct pci_device_id cafe_ids[] = {
  508. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL,
  509. PCI_DEVICE_ID_MARVELL_88ALP01_CCIC) },
  510. { 0, }
  511. };
  512. MODULE_DEVICE_TABLE(pci, cafe_ids);
  513. static struct pci_driver cafe_pci_driver = {
  514. .name = "cafe1000-ccic",
  515. .id_table = cafe_ids,
  516. .probe = cafe_pci_probe,
  517. .remove = cafe_pci_remove,
  518. #ifdef CONFIG_PM
  519. .suspend = cafe_pci_suspend,
  520. .resume = cafe_pci_resume,
  521. #endif
  522. };
  523. static int __init cafe_init(void)
  524. {
  525. int ret;
  526. printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n",
  527. CAFE_VERSION);
  528. ret = pci_register_driver(&cafe_pci_driver);
  529. if (ret) {
  530. printk(KERN_ERR "Unable to register cafe_ccic driver\n");
  531. goto out;
  532. }
  533. ret = 0;
  534. out:
  535. return ret;
  536. }
  537. static void __exit cafe_exit(void)
  538. {
  539. pci_unregister_driver(&cafe_pci_driver);
  540. }
  541. module_init(cafe_init);
  542. module_exit(cafe_exit);