18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * A driver for the CMOS camera controller in the Marvell 88ALP01 "cafe" 48c2ecf20Sopenharmony_ci * multifunction chip. Currently works with the Omnivision OV7670 58c2ecf20Sopenharmony_ci * sensor. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * The data sheet for this device can be found at: 88c2ecf20Sopenharmony_ci * http://wiki.laptop.org/images/5/5c/88ALP01_Datasheet_July_2007.pdf 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright 2006-11 One Laptop Per Child Association, Inc. 118c2ecf20Sopenharmony_ci * Copyright 2006-11 Jonathan Corbet <corbet@lwn.net> 128c2ecf20Sopenharmony_ci * Copyright 2018 Lubomir Rintel <lkundrak@v3.sk> 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Written by Jonathan Corbet, corbet@lwn.net. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * v4l2_device/v4l2_subdev conversion by: 178c2ecf20Sopenharmony_ci * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl> 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci#include <linux/kernel.h> 208c2ecf20Sopenharmony_ci#include <linux/module.h> 218c2ecf20Sopenharmony_ci#include <linux/init.h> 228c2ecf20Sopenharmony_ci#include <linux/pci.h> 238c2ecf20Sopenharmony_ci#include <linux/i2c.h> 248c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 258c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 268c2ecf20Sopenharmony_ci#include <linux/slab.h> 278c2ecf20Sopenharmony_ci#include <linux/videodev2.h> 288c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 298c2ecf20Sopenharmony_ci#include <media/i2c/ov7670.h> 308c2ecf20Sopenharmony_ci#include <linux/device.h> 318c2ecf20Sopenharmony_ci#include <linux/wait.h> 328c2ecf20Sopenharmony_ci#include <linux/delay.h> 338c2ecf20Sopenharmony_ci#include <linux/io.h> 348c2ecf20Sopenharmony_ci#include <linux/clkdev.h> 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#include "mcam-core.h" 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define CAFE_VERSION 0x000002 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * Parameters. 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>"); 458c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Marvell 88ALP01 CMOS Camera Controller driver"); 468c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 478c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("Video"); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistruct cafe_camera { 538c2ecf20Sopenharmony_ci int registered; /* Fully initialized? */ 548c2ecf20Sopenharmony_ci struct mcam_camera mcam; 558c2ecf20Sopenharmony_ci struct pci_dev *pdev; 568c2ecf20Sopenharmony_ci struct i2c_adapter *i2c_adapter; 578c2ecf20Sopenharmony_ci wait_queue_head_t smbus_wait; /* Waiting on i2c events */ 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * Most of the camera controller registers are defined in mcam-core.h, 628c2ecf20Sopenharmony_ci * but the Cafe platform has some additional registers of its own; 638c2ecf20Sopenharmony_ci * they are described here. 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * "General purpose register" has a couple of GPIOs used for sensor 688c2ecf20Sopenharmony_ci * power and reset on OLPC XO 1.0 systems. 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_ci#define REG_GPR 0xb4 718c2ecf20Sopenharmony_ci#define GPR_C1EN 0x00000020 /* Pad 1 (power down) enable */ 728c2ecf20Sopenharmony_ci#define GPR_C0EN 0x00000010 /* Pad 0 (reset) enable */ 738c2ecf20Sopenharmony_ci#define GPR_C1 0x00000002 /* Control 1 value */ 748c2ecf20Sopenharmony_ci/* 758c2ecf20Sopenharmony_ci * Control 0 is wired to reset on OLPC machines. For ov7x sensors, 768c2ecf20Sopenharmony_ci * it is active low. 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_ci#define GPR_C0 0x00000001 /* Control 0 value */ 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* 818c2ecf20Sopenharmony_ci * These registers control the SMBUS module for communicating 828c2ecf20Sopenharmony_ci * with the sensor. 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_ci#define REG_TWSIC0 0xb8 /* TWSI (smbus) control 0 */ 858c2ecf20Sopenharmony_ci#define TWSIC0_EN 0x00000001 /* TWSI enable */ 868c2ecf20Sopenharmony_ci#define TWSIC0_MODE 0x00000002 /* 1 = 16-bit, 0 = 8-bit */ 878c2ecf20Sopenharmony_ci#define TWSIC0_SID 0x000003fc /* Slave ID */ 888c2ecf20Sopenharmony_ci/* 898c2ecf20Sopenharmony_ci * Subtle trickery: the slave ID field starts with bit 2. But the 908c2ecf20Sopenharmony_ci * Linux i2c stack wants to treat the bottommost bit as a separate 918c2ecf20Sopenharmony_ci * read/write bit, which is why slave ID's are usually presented 928c2ecf20Sopenharmony_ci * >>1. For consistency with that behavior, we shift over three 938c2ecf20Sopenharmony_ci * bits instead of two. 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_ci#define TWSIC0_SID_SHIFT 3 968c2ecf20Sopenharmony_ci#define TWSIC0_CLKDIV 0x0007fc00 /* Clock divider */ 978c2ecf20Sopenharmony_ci#define TWSIC0_MASKACK 0x00400000 /* Mask ack from sensor */ 988c2ecf20Sopenharmony_ci#define TWSIC0_OVMAGIC 0x00800000 /* Make it work on OV sensors */ 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define REG_TWSIC1 0xbc /* TWSI control 1 */ 1018c2ecf20Sopenharmony_ci#define TWSIC1_DATA 0x0000ffff /* Data to/from camchip */ 1028c2ecf20Sopenharmony_ci#define TWSIC1_ADDR 0x00ff0000 /* Address (register) */ 1038c2ecf20Sopenharmony_ci#define TWSIC1_ADDR_SHIFT 16 1048c2ecf20Sopenharmony_ci#define TWSIC1_READ 0x01000000 /* Set for read op */ 1058c2ecf20Sopenharmony_ci#define TWSIC1_WSTAT 0x02000000 /* Write status */ 1068c2ecf20Sopenharmony_ci#define TWSIC1_RVALID 0x04000000 /* Read data valid */ 1078c2ecf20Sopenharmony_ci#define TWSIC1_ERROR 0x08000000 /* Something screwed up */ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* 1108c2ecf20Sopenharmony_ci * Here's the weird global control registers 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_ci#define REG_GL_CSR 0x3004 /* Control/status register */ 1138c2ecf20Sopenharmony_ci#define GCSR_SRS 0x00000001 /* SW Reset set */ 1148c2ecf20Sopenharmony_ci#define GCSR_SRC 0x00000002 /* SW Reset clear */ 1158c2ecf20Sopenharmony_ci#define GCSR_MRS 0x00000004 /* Master reset set */ 1168c2ecf20Sopenharmony_ci#define GCSR_MRC 0x00000008 /* HW Reset clear */ 1178c2ecf20Sopenharmony_ci#define GCSR_CCIC_EN 0x00004000 /* CCIC Clock enable */ 1188c2ecf20Sopenharmony_ci#define REG_GL_IMASK 0x300c /* Interrupt mask register */ 1198c2ecf20Sopenharmony_ci#define GIMSK_CCIC_EN 0x00000004 /* CCIC Interrupt enable */ 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define REG_GL_FCR 0x3038 /* GPIO functional control register */ 1228c2ecf20Sopenharmony_ci#define GFCR_GPIO_ON 0x08 /* Camera GPIO enabled */ 1238c2ecf20Sopenharmony_ci#define REG_GL_GPIOR 0x315c /* GPIO register */ 1248c2ecf20Sopenharmony_ci#define GGPIO_OUT 0x80000 /* GPIO output */ 1258c2ecf20Sopenharmony_ci#define GGPIO_VAL 0x00008 /* Output pin value */ 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define REG_LEN (REG_GL_IMASK + 4) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* 1318c2ecf20Sopenharmony_ci * Debugging and related. 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_ci#define cam_err(cam, fmt, arg...) \ 1348c2ecf20Sopenharmony_ci dev_err(&(cam)->pdev->dev, fmt, ##arg); 1358c2ecf20Sopenharmony_ci#define cam_warn(cam, fmt, arg...) \ 1368c2ecf20Sopenharmony_ci dev_warn(&(cam)->pdev->dev, fmt, ##arg); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* -------------------------------------------------------------------- */ 1398c2ecf20Sopenharmony_ci/* 1408c2ecf20Sopenharmony_ci * The I2C/SMBUS interface to the camera itself starts here. The 1418c2ecf20Sopenharmony_ci * controller handles SMBUS itself, presenting a relatively simple register 1428c2ecf20Sopenharmony_ci * interface; all we have to do is to tell it where to route the data. 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_ci#define CAFE_SMBUS_TIMEOUT (HZ) /* generous */ 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic inline struct cafe_camera *to_cam(struct v4l2_device *dev) 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci struct mcam_camera *m = container_of(dev, struct mcam_camera, v4l2_dev); 1498c2ecf20Sopenharmony_ci return container_of(m, struct cafe_camera, mcam); 1508c2ecf20Sopenharmony_ci} 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic int cafe_smbus_write_done(struct mcam_camera *mcam) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci unsigned long flags; 1568c2ecf20Sopenharmony_ci int c1; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci /* 1598c2ecf20Sopenharmony_ci * We must delay after the interrupt, or the controller gets confused 1608c2ecf20Sopenharmony_ci * and never does give us good status. Fortunately, we don't do this 1618c2ecf20Sopenharmony_ci * often. 1628c2ecf20Sopenharmony_ci */ 1638c2ecf20Sopenharmony_ci udelay(20); 1648c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 1658c2ecf20Sopenharmony_ci c1 = mcam_reg_read(mcam, REG_TWSIC1); 1668c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 1678c2ecf20Sopenharmony_ci return (c1 & (TWSIC1_WSTAT|TWSIC1_ERROR)) != TWSIC1_WSTAT; 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic int cafe_smbus_write_data(struct cafe_camera *cam, 1718c2ecf20Sopenharmony_ci u16 addr, u8 command, u8 value) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci unsigned int rval; 1748c2ecf20Sopenharmony_ci unsigned long flags; 1758c2ecf20Sopenharmony_ci struct mcam_camera *mcam = &cam->mcam; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 1788c2ecf20Sopenharmony_ci rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID); 1798c2ecf20Sopenharmony_ci rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */ 1808c2ecf20Sopenharmony_ci /* 1818c2ecf20Sopenharmony_ci * Marvell sez set clkdiv to all 1's for now. 1828c2ecf20Sopenharmony_ci */ 1838c2ecf20Sopenharmony_ci rval |= TWSIC0_CLKDIV; 1848c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_TWSIC0, rval); 1858c2ecf20Sopenharmony_ci (void) mcam_reg_read(mcam, REG_TWSIC1); /* force write */ 1868c2ecf20Sopenharmony_ci rval = value | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR); 1878c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_TWSIC1, rval); 1888c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci /* Unfortunately, reading TWSIC1 too soon after sending a command 1918c2ecf20Sopenharmony_ci * causes the device to die. 1928c2ecf20Sopenharmony_ci * Use a busy-wait because we often send a large quantity of small 1938c2ecf20Sopenharmony_ci * commands at-once; using msleep() would cause a lot of context 1948c2ecf20Sopenharmony_ci * switches which take longer than 2ms, resulting in a noticeable 1958c2ecf20Sopenharmony_ci * boot-time and capture-start delays. 1968c2ecf20Sopenharmony_ci */ 1978c2ecf20Sopenharmony_ci mdelay(2); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* 2008c2ecf20Sopenharmony_ci * Another sad fact is that sometimes, commands silently complete but 2018c2ecf20Sopenharmony_ci * cafe_smbus_write_done() never becomes aware of this. 2028c2ecf20Sopenharmony_ci * This happens at random and appears to possible occur with any 2038c2ecf20Sopenharmony_ci * command. 2048c2ecf20Sopenharmony_ci * We don't understand why this is. We work around this issue 2058c2ecf20Sopenharmony_ci * with the timeout in the wait below, assuming that all commands 2068c2ecf20Sopenharmony_ci * complete within the timeout. 2078c2ecf20Sopenharmony_ci */ 2088c2ecf20Sopenharmony_ci wait_event_timeout(cam->smbus_wait, cafe_smbus_write_done(mcam), 2098c2ecf20Sopenharmony_ci CAFE_SMBUS_TIMEOUT); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 2128c2ecf20Sopenharmony_ci rval = mcam_reg_read(mcam, REG_TWSIC1); 2138c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci if (rval & TWSIC1_WSTAT) { 2168c2ecf20Sopenharmony_ci cam_err(cam, "SMBUS write (%02x/%02x/%02x) timed out\n", addr, 2178c2ecf20Sopenharmony_ci command, value); 2188c2ecf20Sopenharmony_ci return -EIO; 2198c2ecf20Sopenharmony_ci } 2208c2ecf20Sopenharmony_ci if (rval & TWSIC1_ERROR) { 2218c2ecf20Sopenharmony_ci cam_err(cam, "SMBUS write (%02x/%02x/%02x) error\n", addr, 2228c2ecf20Sopenharmony_ci command, value); 2238c2ecf20Sopenharmony_ci return -EIO; 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci return 0; 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistatic int cafe_smbus_read_done(struct mcam_camera *mcam) 2318c2ecf20Sopenharmony_ci{ 2328c2ecf20Sopenharmony_ci unsigned long flags; 2338c2ecf20Sopenharmony_ci int c1; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci /* 2368c2ecf20Sopenharmony_ci * We must delay after the interrupt, or the controller gets confused 2378c2ecf20Sopenharmony_ci * and never does give us good status. Fortunately, we don't do this 2388c2ecf20Sopenharmony_ci * often. 2398c2ecf20Sopenharmony_ci */ 2408c2ecf20Sopenharmony_ci udelay(20); 2418c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 2428c2ecf20Sopenharmony_ci c1 = mcam_reg_read(mcam, REG_TWSIC1); 2438c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 2448c2ecf20Sopenharmony_ci return c1 & (TWSIC1_RVALID|TWSIC1_ERROR); 2458c2ecf20Sopenharmony_ci} 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic int cafe_smbus_read_data(struct cafe_camera *cam, 2508c2ecf20Sopenharmony_ci u16 addr, u8 command, u8 *value) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci unsigned int rval; 2538c2ecf20Sopenharmony_ci unsigned long flags; 2548c2ecf20Sopenharmony_ci struct mcam_camera *mcam = &cam->mcam; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 2578c2ecf20Sopenharmony_ci rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID); 2588c2ecf20Sopenharmony_ci rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */ 2598c2ecf20Sopenharmony_ci /* 2608c2ecf20Sopenharmony_ci * Marvel sez set clkdiv to all 1's for now. 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_ci rval |= TWSIC0_CLKDIV; 2638c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_TWSIC0, rval); 2648c2ecf20Sopenharmony_ci (void) mcam_reg_read(mcam, REG_TWSIC1); /* force write */ 2658c2ecf20Sopenharmony_ci rval = TWSIC1_READ | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR); 2668c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_TWSIC1, rval); 2678c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci wait_event_timeout(cam->smbus_wait, 2708c2ecf20Sopenharmony_ci cafe_smbus_read_done(mcam), CAFE_SMBUS_TIMEOUT); 2718c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 2728c2ecf20Sopenharmony_ci rval = mcam_reg_read(mcam, REG_TWSIC1); 2738c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci if (rval & TWSIC1_ERROR) { 2768c2ecf20Sopenharmony_ci cam_err(cam, "SMBUS read (%02x/%02x) error\n", addr, command); 2778c2ecf20Sopenharmony_ci return -EIO; 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_ci if (!(rval & TWSIC1_RVALID)) { 2808c2ecf20Sopenharmony_ci cam_err(cam, "SMBUS read (%02x/%02x) timed out\n", addr, 2818c2ecf20Sopenharmony_ci command); 2828c2ecf20Sopenharmony_ci return -EIO; 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci *value = rval & 0xff; 2858c2ecf20Sopenharmony_ci return 0; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/* 2898c2ecf20Sopenharmony_ci * Perform a transfer over SMBUS. This thing is called under 2908c2ecf20Sopenharmony_ci * the i2c bus lock, so we shouldn't race with ourselves... 2918c2ecf20Sopenharmony_ci */ 2928c2ecf20Sopenharmony_cistatic int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr, 2938c2ecf20Sopenharmony_ci unsigned short flags, char rw, u8 command, 2948c2ecf20Sopenharmony_ci int size, union i2c_smbus_data *data) 2958c2ecf20Sopenharmony_ci{ 2968c2ecf20Sopenharmony_ci struct cafe_camera *cam = i2c_get_adapdata(adapter); 2978c2ecf20Sopenharmony_ci int ret = -EINVAL; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci /* 3008c2ecf20Sopenharmony_ci * This interface would appear to only do byte data ops. OK 3018c2ecf20Sopenharmony_ci * it can do word too, but the cam chip has no use for that. 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_ci if (size != I2C_SMBUS_BYTE_DATA) { 3048c2ecf20Sopenharmony_ci cam_err(cam, "funky xfer size %d\n", size); 3058c2ecf20Sopenharmony_ci return -EINVAL; 3068c2ecf20Sopenharmony_ci } 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci if (rw == I2C_SMBUS_WRITE) 3098c2ecf20Sopenharmony_ci ret = cafe_smbus_write_data(cam, addr, command, data->byte); 3108c2ecf20Sopenharmony_ci else if (rw == I2C_SMBUS_READ) 3118c2ecf20Sopenharmony_ci ret = cafe_smbus_read_data(cam, addr, command, &data->byte); 3128c2ecf20Sopenharmony_ci return ret; 3138c2ecf20Sopenharmony_ci} 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_cistatic void cafe_smbus_enable_irq(struct cafe_camera *cam) 3178c2ecf20Sopenharmony_ci{ 3188c2ecf20Sopenharmony_ci unsigned long flags; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci spin_lock_irqsave(&cam->mcam.dev_lock, flags); 3218c2ecf20Sopenharmony_ci mcam_reg_set_bit(&cam->mcam, REG_IRQMASK, TWSIIRQS); 3228c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&cam->mcam.dev_lock, flags); 3238c2ecf20Sopenharmony_ci} 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_cistatic u32 cafe_smbus_func(struct i2c_adapter *adapter) 3268c2ecf20Sopenharmony_ci{ 3278c2ecf20Sopenharmony_ci return I2C_FUNC_SMBUS_READ_BYTE_DATA | 3288c2ecf20Sopenharmony_ci I2C_FUNC_SMBUS_WRITE_BYTE_DATA; 3298c2ecf20Sopenharmony_ci} 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistatic const struct i2c_algorithm cafe_smbus_algo = { 3328c2ecf20Sopenharmony_ci .smbus_xfer = cafe_smbus_xfer, 3338c2ecf20Sopenharmony_ci .functionality = cafe_smbus_func 3348c2ecf20Sopenharmony_ci}; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistatic int cafe_smbus_setup(struct cafe_camera *cam) 3378c2ecf20Sopenharmony_ci{ 3388c2ecf20Sopenharmony_ci struct i2c_adapter *adap; 3398c2ecf20Sopenharmony_ci int ret; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci adap = kzalloc(sizeof(*adap), GFP_KERNEL); 3428c2ecf20Sopenharmony_ci if (adap == NULL) 3438c2ecf20Sopenharmony_ci return -ENOMEM; 3448c2ecf20Sopenharmony_ci adap->owner = THIS_MODULE; 3458c2ecf20Sopenharmony_ci adap->algo = &cafe_smbus_algo; 3468c2ecf20Sopenharmony_ci strscpy(adap->name, "cafe_ccic", sizeof(adap->name)); 3478c2ecf20Sopenharmony_ci adap->dev.parent = &cam->pdev->dev; 3488c2ecf20Sopenharmony_ci i2c_set_adapdata(adap, cam); 3498c2ecf20Sopenharmony_ci ret = i2c_add_adapter(adap); 3508c2ecf20Sopenharmony_ci if (ret) { 3518c2ecf20Sopenharmony_ci printk(KERN_ERR "Unable to register cafe i2c adapter\n"); 3528c2ecf20Sopenharmony_ci kfree(adap); 3538c2ecf20Sopenharmony_ci return ret; 3548c2ecf20Sopenharmony_ci } 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci cam->i2c_adapter = adap; 3578c2ecf20Sopenharmony_ci cafe_smbus_enable_irq(cam); 3588c2ecf20Sopenharmony_ci return 0; 3598c2ecf20Sopenharmony_ci} 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistatic void cafe_smbus_shutdown(struct cafe_camera *cam) 3628c2ecf20Sopenharmony_ci{ 3638c2ecf20Sopenharmony_ci i2c_del_adapter(cam->i2c_adapter); 3648c2ecf20Sopenharmony_ci kfree(cam->i2c_adapter); 3658c2ecf20Sopenharmony_ci} 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/* 3698c2ecf20Sopenharmony_ci * Controller-level stuff 3708c2ecf20Sopenharmony_ci */ 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistatic void cafe_ctlr_init(struct mcam_camera *mcam) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci unsigned long flags; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 3778c2ecf20Sopenharmony_ci /* 3788c2ecf20Sopenharmony_ci * Added magic to bring up the hardware on the B-Test board 3798c2ecf20Sopenharmony_ci */ 3808c2ecf20Sopenharmony_ci mcam_reg_write(mcam, 0x3038, 0x8); 3818c2ecf20Sopenharmony_ci mcam_reg_write(mcam, 0x315c, 0x80008); 3828c2ecf20Sopenharmony_ci /* 3838c2ecf20Sopenharmony_ci * Go through the dance needed to wake the device up. 3848c2ecf20Sopenharmony_ci * Note that these registers are global and shared 3858c2ecf20Sopenharmony_ci * with the NAND and SD devices. Interaction between the 3868c2ecf20Sopenharmony_ci * three still needs to be examined. 3878c2ecf20Sopenharmony_ci */ 3888c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRS|GCSR_MRS); /* Needed? */ 3898c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRC|GCSR_MRC); 3908c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRC|GCSR_MRS); 3918c2ecf20Sopenharmony_ci /* 3928c2ecf20Sopenharmony_ci * Here we must wait a bit for the controller to come around. 3938c2ecf20Sopenharmony_ci */ 3948c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 3958c2ecf20Sopenharmony_ci msleep(5); 3968c2ecf20Sopenharmony_ci spin_lock_irqsave(&mcam->dev_lock, flags); 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_CSR, GCSR_CCIC_EN|GCSR_SRC|GCSR_MRC); 3998c2ecf20Sopenharmony_ci mcam_reg_set_bit(mcam, REG_GL_IMASK, GIMSK_CCIC_EN); 4008c2ecf20Sopenharmony_ci /* 4018c2ecf20Sopenharmony_ci * Mask all interrupts. 4028c2ecf20Sopenharmony_ci */ 4038c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_IRQMASK, 0); 4048c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&mcam->dev_lock, flags); 4058c2ecf20Sopenharmony_ci} 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistatic int cafe_ctlr_power_up(struct mcam_camera *mcam) 4098c2ecf20Sopenharmony_ci{ 4108c2ecf20Sopenharmony_ci /* 4118c2ecf20Sopenharmony_ci * Part one of the sensor dance: turn the global 4128c2ecf20Sopenharmony_ci * GPIO signal on. 4138c2ecf20Sopenharmony_ci */ 4148c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_FCR, GFCR_GPIO_ON); 4158c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_GPIOR, GGPIO_OUT|GGPIO_VAL); 4168c2ecf20Sopenharmony_ci /* 4178c2ecf20Sopenharmony_ci * Put the sensor into operational mode (assumes OLPC-style 4188c2ecf20Sopenharmony_ci * wiring). Control 0 is reset - set to 1 to operate. 4198c2ecf20Sopenharmony_ci * Control 1 is power down, set to 0 to operate. 4208c2ecf20Sopenharmony_ci */ 4218c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */ 4228c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci return 0; 4258c2ecf20Sopenharmony_ci} 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cistatic void cafe_ctlr_power_down(struct mcam_camera *mcam) 4288c2ecf20Sopenharmony_ci{ 4298c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1); 4308c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_FCR, GFCR_GPIO_ON); 4318c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_GL_GPIOR, GGPIO_OUT); 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci/* 4378c2ecf20Sopenharmony_ci * The platform interrupt handler. 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_cistatic irqreturn_t cafe_irq(int irq, void *data) 4408c2ecf20Sopenharmony_ci{ 4418c2ecf20Sopenharmony_ci struct cafe_camera *cam = data; 4428c2ecf20Sopenharmony_ci struct mcam_camera *mcam = &cam->mcam; 4438c2ecf20Sopenharmony_ci unsigned int irqs, handled; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci spin_lock(&mcam->dev_lock); 4468c2ecf20Sopenharmony_ci irqs = mcam_reg_read(mcam, REG_IRQSTAT); 4478c2ecf20Sopenharmony_ci handled = cam->registered && mccic_irq(mcam, irqs); 4488c2ecf20Sopenharmony_ci if (irqs & TWSIIRQS) { 4498c2ecf20Sopenharmony_ci mcam_reg_write(mcam, REG_IRQSTAT, TWSIIRQS); 4508c2ecf20Sopenharmony_ci wake_up(&cam->smbus_wait); 4518c2ecf20Sopenharmony_ci handled = 1; 4528c2ecf20Sopenharmony_ci } 4538c2ecf20Sopenharmony_ci spin_unlock(&mcam->dev_lock); 4548c2ecf20Sopenharmony_ci return IRQ_RETVAL(handled); 4558c2ecf20Sopenharmony_ci} 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci/* -------------------------------------------------------------------------- */ 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_cistatic struct ov7670_config sensor_cfg = { 4608c2ecf20Sopenharmony_ci /* 4618c2ecf20Sopenharmony_ci * Exclude QCIF mode, because it only captures a tiny portion 4628c2ecf20Sopenharmony_ci * of the sensor FOV 4638c2ecf20Sopenharmony_ci */ 4648c2ecf20Sopenharmony_ci .min_width = 320, 4658c2ecf20Sopenharmony_ci .min_height = 240, 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci /* 4688c2ecf20Sopenharmony_ci * Set the clock speed for the XO 1; I don't believe this 4698c2ecf20Sopenharmony_ci * driver has ever run anywhere else. 4708c2ecf20Sopenharmony_ci */ 4718c2ecf20Sopenharmony_ci .clock_speed = 45, 4728c2ecf20Sopenharmony_ci .use_smbus = 1, 4738c2ecf20Sopenharmony_ci}; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_cistatic struct i2c_board_info ov7670_info = { 4768c2ecf20Sopenharmony_ci .type = "ov7670", 4778c2ecf20Sopenharmony_ci .addr = 0x42 >> 1, 4788c2ecf20Sopenharmony_ci .platform_data = &sensor_cfg, 4798c2ecf20Sopenharmony_ci}; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci/* -------------------------------------------------------------------------- */ 4828c2ecf20Sopenharmony_ci/* 4838c2ecf20Sopenharmony_ci * PCI interface stuff. 4848c2ecf20Sopenharmony_ci */ 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic int cafe_pci_probe(struct pci_dev *pdev, 4878c2ecf20Sopenharmony_ci const struct pci_device_id *id) 4888c2ecf20Sopenharmony_ci{ 4898c2ecf20Sopenharmony_ci int ret; 4908c2ecf20Sopenharmony_ci struct cafe_camera *cam; 4918c2ecf20Sopenharmony_ci struct mcam_camera *mcam; 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci /* 4948c2ecf20Sopenharmony_ci * Start putting together one of our big camera structures. 4958c2ecf20Sopenharmony_ci */ 4968c2ecf20Sopenharmony_ci ret = -ENOMEM; 4978c2ecf20Sopenharmony_ci cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL); 4988c2ecf20Sopenharmony_ci if (cam == NULL) 4998c2ecf20Sopenharmony_ci goto out; 5008c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, cam); 5018c2ecf20Sopenharmony_ci cam->pdev = pdev; 5028c2ecf20Sopenharmony_ci mcam = &cam->mcam; 5038c2ecf20Sopenharmony_ci mcam->chip_id = MCAM_CAFE; 5048c2ecf20Sopenharmony_ci spin_lock_init(&mcam->dev_lock); 5058c2ecf20Sopenharmony_ci init_waitqueue_head(&cam->smbus_wait); 5068c2ecf20Sopenharmony_ci mcam->plat_power_up = cafe_ctlr_power_up; 5078c2ecf20Sopenharmony_ci mcam->plat_power_down = cafe_ctlr_power_down; 5088c2ecf20Sopenharmony_ci mcam->dev = &pdev->dev; 5098c2ecf20Sopenharmony_ci snprintf(mcam->bus_info, sizeof(mcam->bus_info), "PCI:%s", pci_name(pdev)); 5108c2ecf20Sopenharmony_ci /* 5118c2ecf20Sopenharmony_ci * Vmalloc mode for buffers is traditional with this driver. 5128c2ecf20Sopenharmony_ci * We *might* be able to run DMA_contig, especially on a system 5138c2ecf20Sopenharmony_ci * with CMA in it. 5148c2ecf20Sopenharmony_ci */ 5158c2ecf20Sopenharmony_ci mcam->buffer_mode = B_vmalloc; 5168c2ecf20Sopenharmony_ci /* 5178c2ecf20Sopenharmony_ci * Get set up on the PCI bus. 5188c2ecf20Sopenharmony_ci */ 5198c2ecf20Sopenharmony_ci ret = pci_enable_device(pdev); 5208c2ecf20Sopenharmony_ci if (ret) 5218c2ecf20Sopenharmony_ci goto out_free; 5228c2ecf20Sopenharmony_ci pci_set_master(pdev); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci ret = -EIO; 5258c2ecf20Sopenharmony_ci mcam->regs = pci_iomap(pdev, 0, 0); 5268c2ecf20Sopenharmony_ci if (!mcam->regs) { 5278c2ecf20Sopenharmony_ci printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n"); 5288c2ecf20Sopenharmony_ci goto out_disable; 5298c2ecf20Sopenharmony_ci } 5308c2ecf20Sopenharmony_ci mcam->regs_size = pci_resource_len(pdev, 0); 5318c2ecf20Sopenharmony_ci ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam); 5328c2ecf20Sopenharmony_ci if (ret) 5338c2ecf20Sopenharmony_ci goto out_iounmap; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci /* 5368c2ecf20Sopenharmony_ci * Initialize the controller. 5378c2ecf20Sopenharmony_ci */ 5388c2ecf20Sopenharmony_ci cafe_ctlr_init(mcam); 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci /* 5418c2ecf20Sopenharmony_ci * Set up I2C/SMBUS communications. We have to drop the mutex here 5428c2ecf20Sopenharmony_ci * because the sensor could attach in this call chain, leading to 5438c2ecf20Sopenharmony_ci * unsightly deadlocks. 5448c2ecf20Sopenharmony_ci */ 5458c2ecf20Sopenharmony_ci ret = cafe_smbus_setup(cam); 5468c2ecf20Sopenharmony_ci if (ret) 5478c2ecf20Sopenharmony_ci goto out_pdown; 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci mcam->asd.match_type = V4L2_ASYNC_MATCH_I2C; 5508c2ecf20Sopenharmony_ci mcam->asd.match.i2c.adapter_id = i2c_adapter_id(cam->i2c_adapter); 5518c2ecf20Sopenharmony_ci mcam->asd.match.i2c.address = ov7670_info.addr; 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci ret = mccic_register(mcam); 5548c2ecf20Sopenharmony_ci if (ret) 5558c2ecf20Sopenharmony_ci goto out_smbus_shutdown; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci clkdev_create(mcam->mclk, "xclk", "%d-%04x", 5588c2ecf20Sopenharmony_ci i2c_adapter_id(cam->i2c_adapter), ov7670_info.addr); 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_ci if (!IS_ERR(i2c_new_client_device(cam->i2c_adapter, &ov7670_info))) { 5618c2ecf20Sopenharmony_ci cam->registered = 1; 5628c2ecf20Sopenharmony_ci return 0; 5638c2ecf20Sopenharmony_ci } 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci mccic_shutdown(mcam); 5668c2ecf20Sopenharmony_ciout_smbus_shutdown: 5678c2ecf20Sopenharmony_ci cafe_smbus_shutdown(cam); 5688c2ecf20Sopenharmony_ciout_pdown: 5698c2ecf20Sopenharmony_ci cafe_ctlr_power_down(mcam); 5708c2ecf20Sopenharmony_ci free_irq(pdev->irq, cam); 5718c2ecf20Sopenharmony_ciout_iounmap: 5728c2ecf20Sopenharmony_ci pci_iounmap(pdev, mcam->regs); 5738c2ecf20Sopenharmony_ciout_disable: 5748c2ecf20Sopenharmony_ci pci_disable_device(pdev); 5758c2ecf20Sopenharmony_ciout_free: 5768c2ecf20Sopenharmony_ci kfree(cam); 5778c2ecf20Sopenharmony_ciout: 5788c2ecf20Sopenharmony_ci return ret; 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci/* 5838c2ecf20Sopenharmony_ci * Shut down an initialized device 5848c2ecf20Sopenharmony_ci */ 5858c2ecf20Sopenharmony_cistatic void cafe_shutdown(struct cafe_camera *cam) 5868c2ecf20Sopenharmony_ci{ 5878c2ecf20Sopenharmony_ci mccic_shutdown(&cam->mcam); 5888c2ecf20Sopenharmony_ci cafe_smbus_shutdown(cam); 5898c2ecf20Sopenharmony_ci free_irq(cam->pdev->irq, cam); 5908c2ecf20Sopenharmony_ci pci_iounmap(cam->pdev, cam->mcam.regs); 5918c2ecf20Sopenharmony_ci} 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_cistatic void cafe_pci_remove(struct pci_dev *pdev) 5958c2ecf20Sopenharmony_ci{ 5968c2ecf20Sopenharmony_ci struct cafe_camera *cam = pci_get_drvdata(pdev); 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci if (cam == NULL) { 5998c2ecf20Sopenharmony_ci printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev); 6008c2ecf20Sopenharmony_ci return; 6018c2ecf20Sopenharmony_ci } 6028c2ecf20Sopenharmony_ci cafe_shutdown(cam); 6038c2ecf20Sopenharmony_ci kfree(cam); 6048c2ecf20Sopenharmony_ci} 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci/* 6088c2ecf20Sopenharmony_ci * Basic power management. 6098c2ecf20Sopenharmony_ci */ 6108c2ecf20Sopenharmony_cistatic int __maybe_unused cafe_pci_suspend(struct device *dev) 6118c2ecf20Sopenharmony_ci{ 6128c2ecf20Sopenharmony_ci struct cafe_camera *cam = dev_get_drvdata(dev); 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci mccic_suspend(&cam->mcam); 6158c2ecf20Sopenharmony_ci return 0; 6168c2ecf20Sopenharmony_ci} 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_cistatic int __maybe_unused cafe_pci_resume(struct device *dev) 6208c2ecf20Sopenharmony_ci{ 6218c2ecf20Sopenharmony_ci struct cafe_camera *cam = dev_get_drvdata(dev); 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci cafe_ctlr_init(&cam->mcam); 6248c2ecf20Sopenharmony_ci return mccic_resume(&cam->mcam); 6258c2ecf20Sopenharmony_ci} 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_cistatic const struct pci_device_id cafe_ids[] = { 6288c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 6298c2ecf20Sopenharmony_ci PCI_DEVICE_ID_MARVELL_88ALP01_CCIC) }, 6308c2ecf20Sopenharmony_ci { 0, } 6318c2ecf20Sopenharmony_ci}; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, cafe_ids); 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(cafe_pci_pm_ops, cafe_pci_suspend, cafe_pci_resume); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_cistatic struct pci_driver cafe_pci_driver = { 6388c2ecf20Sopenharmony_ci .name = "cafe1000-ccic", 6398c2ecf20Sopenharmony_ci .id_table = cafe_ids, 6408c2ecf20Sopenharmony_ci .probe = cafe_pci_probe, 6418c2ecf20Sopenharmony_ci .remove = cafe_pci_remove, 6428c2ecf20Sopenharmony_ci .driver.pm = &cafe_pci_pm_ops, 6438c2ecf20Sopenharmony_ci}; 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_cistatic int __init cafe_init(void) 6498c2ecf20Sopenharmony_ci{ 6508c2ecf20Sopenharmony_ci int ret; 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n", 6538c2ecf20Sopenharmony_ci CAFE_VERSION); 6548c2ecf20Sopenharmony_ci ret = pci_register_driver(&cafe_pci_driver); 6558c2ecf20Sopenharmony_ci if (ret) { 6568c2ecf20Sopenharmony_ci printk(KERN_ERR "Unable to register cafe_ccic driver\n"); 6578c2ecf20Sopenharmony_ci goto out; 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci ret = 0; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ciout: 6628c2ecf20Sopenharmony_ci return ret; 6638c2ecf20Sopenharmony_ci} 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_cistatic void __exit cafe_exit(void) 6678c2ecf20Sopenharmony_ci{ 6688c2ecf20Sopenharmony_ci pci_unregister_driver(&cafe_pci_driver); 6698c2ecf20Sopenharmony_ci} 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_cimodule_init(cafe_init); 6728c2ecf20Sopenharmony_cimodule_exit(cafe_exit); 673