Files
vi-kernel/vvcam/soc/vsi/soc_i2c_dev.c
2022-09-13 10:34:22 +08:00

147 lines
4.1 KiB
C
Executable File

/****************************************************************************
*
* The MIT License (MIT)
*
* Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************
*
* The GPL License (GPL)
*
* Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program;
*
*****************************************************************************
*
* Note: This software is released under dual MIT and GPL licenses. A
* recipient may use this file under the terms of either the MIT license or
* GPL License. If you wish to use only one license not the other, you can
* indicate your decision by deleting one of the above license notices in your
* version of this file.
*
*****************************************************************************/
#include <linux/platform_device.h>
static void soc_gpio_i2c_release(struct device *dev)
{
pr_info("enter %s\n", __func__);
return;
}
static struct resource soc_gpio_i2c0_resource[] = {
[0] = {
.start = 0x00,
.end = 0x00,
.flags = IORESOURCE_MEM,
},
};
static struct platform_device soc_gpio_i2c0_pdev = {
.name = "soc_gpio_i2c",
.id = -1,
.resource = soc_gpio_i2c0_resource,
.num_resources = 1,
.dev.release = soc_gpio_i2c_release,
};
static struct resource soc_gpio_i2c1_resource[] = {
[0] = {
.start = 0x00,
.end = 0x00,
.flags = IORESOURCE_MEM,
},
};
static struct platform_device soc_gpio_i2c1_pdev = {
.name = "soc_gpio_i2c",
.id = -1,
.resource = soc_gpio_i2c1_resource,
.num_resources = 1,
.dev.release = soc_gpio_i2c_release,
};
int soc_gpio_i2c_register_bus(unsigned int index,unsigned int bus,unsigned long base_addr, unsigned int size,
void * virt_base)
{
int ret = 0;
struct platform_device * i2c_pdev;
pr_info("enter %s\n", __func__);
switch(index)
{
case 0:
i2c_pdev = &soc_gpio_i2c0_pdev;
break;
case 1:
i2c_pdev = &soc_gpio_i2c1_pdev;
break;
default :
return -1;
}
i2c_pdev->id = bus;
i2c_pdev->resource[0].start = base_addr;
i2c_pdev->resource[0].end = base_addr + size - 1;
i2c_pdev->resource[0].name = virt_base;
ret = platform_device_register(i2c_pdev);
pr_info("exit %s\n", __func__);
return ret;
}
void soc_gpio_i2c_unregister_bus(unsigned int index)
{
struct platform_device * i2c_pdev;
switch(index)
{
case 0:
i2c_pdev = &soc_gpio_i2c0_pdev;
break;
case 1:
i2c_pdev = &soc_gpio_i2c1_pdev;
break;
default :
return;
}
platform_device_unregister(i2c_pdev);
return ;
}