cafe-driver.c 17 KB

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