20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/i2c.h>
27 #include <linux/slab.h>
28 #include <linux/videodev2.h>
31 #include <linux/device.h>
32 #include <linux/wait.h>
38 #define CAFE_VERSION 0x000002
70 #define GPR_C1EN 0x00000020
71 #define GPR_C0EN 0x00000010
72 #define GPR_C1 0x00000002
77 #define GPR_C0 0x00000001
83 #define REG_TWSIC0 0xb8
84 #define TWSIC0_EN 0x00000001
85 #define TWSIC0_MODE 0x00000002
86 #define TWSIC0_SID 0x000003fc
94 #define TWSIC0_SID_SHIFT 3
95 #define TWSIC0_CLKDIV 0x0007fc00
96 #define TWSIC0_MASKACK 0x00400000
97 #define TWSIC0_OVMAGIC 0x00800000
99 #define REG_TWSIC1 0xbc
100 #define TWSIC1_DATA 0x0000ffff
101 #define TWSIC1_ADDR 0x00ff0000
102 #define TWSIC1_ADDR_SHIFT 16
103 #define TWSIC1_READ 0x01000000
104 #define TWSIC1_WSTAT 0x02000000
105 #define TWSIC1_RVALID 0x04000000
106 #define TWSIC1_ERROR 0x08000000
111 #define REG_GL_CSR 0x3004
112 #define GCSR_SRS 0x00000001
113 #define GCSR_SRC 0x00000002
114 #define GCSR_MRS 0x00000004
115 #define GCSR_MRC 0x00000008
116 #define GCSR_CCIC_EN 0x00004000
117 #define REG_GL_IMASK 0x300c
118 #define GIMSK_CCIC_EN 0x00000004
120 #define REG_GL_FCR 0x3038
121 #define GFCR_GPIO_ON 0x08
122 #define REG_GL_GPIOR 0x315c
123 #define GGPIO_OUT 0x80000
124 #define GGPIO_VAL 0x00008
126 #define REG_LEN (REG_GL_IMASK + 4)
132 #define cam_err(cam, fmt, arg...) \
133 dev_err(&(cam)->pdev->dev, fmt, ##arg);
134 #define cam_warn(cam, fmt, arg...) \
135 dev_warn(&(cam)->pdev->dev, fmt, ##arg);
143 #define CAFE_SMBUS_TIMEOUT (HZ)
152 static int cafe_smbus_write_done(
struct mcam_camera *mcam)
165 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
187 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
212 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
215 cam_err(cam,
"SMBUS write (%02x/%02x/%02x) timed out\n", addr,
220 cam_err(cam,
"SMBUS write (%02x/%02x/%02x) error\n", addr,
229 static int cafe_smbus_read_done(
struct mcam_camera *mcam)
242 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
248 static int cafe_smbus_read_data(
struct cafe_camera *cam,
249 u16 addr,
u8 command,
u8 *value)
266 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
272 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
275 cam_err(cam,
"SMBUS read (%02x/%02x) error\n", addr, command);
279 cam_err(cam,
"SMBUS read (%02x/%02x) timed out\n", addr,
283 *value = rval & 0xff;
292 unsigned short flags,
char rw,
u8 command,
295 struct cafe_camera *cam = i2c_get_adapdata(adapter);
303 cam_err(cam,
"funky xfer size %d\n", size);
308 ret = cafe_smbus_write_data(cam, addr, command, data->
byte);
310 ret = cafe_smbus_read_data(cam, addr, command, &data->
byte);
315 static void cafe_smbus_enable_irq(
struct cafe_camera *cam)
321 spin_unlock_irqrestore(&cam->
mcam.dev_lock, flags);
331 .smbus_xfer = cafe_smbus_xfer,
332 .functionality = cafe_smbus_func
335 static int cafe_smbus_setup(
struct cafe_camera *cam)
343 cam->
mcam.i2c_adapter = adap;
344 cafe_smbus_enable_irq(cam);
346 adap->
algo = &cafe_smbus_algo;
348 adap->
dev.parent = &cam->
pdev->dev;
349 i2c_set_adapdata(adap, cam);
356 static void cafe_smbus_shutdown(
struct cafe_camera *cam)
367 static void cafe_ctlr_init(
struct mcam_camera *mcam)
375 mcam_reg_write(mcam, 0x3038, 0x8);
376 mcam_reg_write(mcam, 0x315c, 0x80008);
389 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
399 spin_unlock_irqrestore(&mcam->
dev_lock, flags);
403 static void cafe_ctlr_power_up(
struct mcam_camera *mcam)
420 static void cafe_ctlr_power_down(
struct mcam_camera *mcam)
436 unsigned int irqs, handled;
456 static int cafe_pci_probe(
struct pci_dev *pdev,
499 mcam->
regs = pci_iomap(pdev, 0, 0);
512 cafe_ctlr_init(mcam);
513 cafe_ctlr_power_up(mcam);
519 ret = cafe_smbus_setup(cam);
529 cafe_smbus_shutdown(cam);
531 cafe_ctlr_power_down(mcam);
550 cafe_smbus_shutdown(cam);
556 static void cafe_pci_remove(
struct pci_dev *pdev)
583 mccic_suspend(&cam->
mcam);
589 static int cafe_pci_resume(
struct pci_dev *pdev)
599 cam_warn(cam,
"Unable to re-enable device on resume!\n");
602 cafe_ctlr_init(&cam->
mcam);
603 return mccic_resume(&cam->
mcam);
617 .name =
"cafe1000-ccic",
618 .id_table = cafe_ids,
619 .probe = cafe_pci_probe,
620 .remove = cafe_pci_remove,
622 .suspend = cafe_pci_suspend,
623 .resume = cafe_pci_resume,
630 static int __init cafe_init(
void)
636 ret = pci_register_driver(&cafe_pci_driver);
648 static void __exit cafe_exit(
void)