bl40: g12a/sm1: add m4 bringup path [1/3]

PD#SWPL-12964

Problem:
bring up m4

Solution:
add kernel driver

Verify:
U209+S905D3

Change-Id: Iaa57f24c919af013581b8e3faffb0b57f5af10ed
Signed-off-by: Shunzhou Jiang <shunzhou.jiang@amlogic.com>
This commit is contained in:
Shunzhou Jiang
2019-08-20 20:09:13 +08:00
committed by Luke Go
parent 5e1ec0d89d
commit c045252a9d
13 changed files with 206 additions and 0 deletions

View File

@@ -14891,3 +14891,9 @@ F: Documentation/devicetree/binding/input/touchscreen/sx8650.txt
AMLOGIC LCD EXTERN DRIVER
M: Shaochan Liu <shaochan.liu@amlogic.com>
F: drivers/amlogic/media/vout/lcd/lcd_extern/i2c_CS602.c
AMLOGIC SM1/G12A BL40 BOOTUP DRIVER
M: shunzhou jiang <shunzhou.jiang@amlogic.com>
F: drivers/amlogic/firmware/bl40_module.c
F: drivers/amlogic/firmware/Makefile
F: drivers/amlogic/firmware/Kconfig

View File

@@ -503,6 +503,11 @@
#thermal-sensor-cells = <1>;
};
bl40: bl40 {
compatible = "amlogic, bl40-bootup";
status = "okay";
};
soc {
compatible = "simple-bus";
#address-cells = <1>;

View File

@@ -484,6 +484,11 @@
<0xff63c100 0x10>;
};
bl40: bl40 {
compatible = "amlogic, bl40-bootup";
status = "okay";
};
soc {
compatible = "simple-bus";
#address-cells = <1>;

View File

@@ -379,6 +379,7 @@ CONFIG_AMLOGIC_DEFENDKEY=y
CONFIG_AMLOGIC_BATTERY_DUMMY=y
CONFIG_AMLOGIC_CHARGER_DUMMY=y
CONFIG_AMLOGIC_PIXEL_PROBE=y
CONFIG_AMLOGIC_FIRMWARE=y
CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y

View File

@@ -503,6 +503,11 @@
#thermal-sensor-cells = <1>;
};
bl40: bl40 {
compatible = "amlogic, bl40-bootup";
status = "okay";
};
soc {
compatible = "simple-bus";
#address-cells = <2>;

View File

@@ -484,6 +484,11 @@
<0x0 0xff63c100 0x0 0x10>;
};
bl40: bl40 {
compatible = "amlogic, bl40-bootup";
status = "okay";
};
soc {
compatible = "simple-bus";
#address-cells = <2>;

View File

@@ -374,6 +374,7 @@ CONFIG_AMLOGIC_BATTERY_DUMMY=y
CONFIG_AMLOGIC_CHARGER_DUMMY=y
CONFIG_DOLBY_FW=y
CONFIG_AMLOGIC_PIXEL_PROBE=y
CONFIG_AMLOGIC_FIRMWARE=y
CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y

View File

@@ -140,5 +140,7 @@ source "drivers/amlogic/dolby_fw/Kconfig"
source "drivers/amlogic/pixel_probe/Kconfig"
source "drivers/amlogic/firmware/Kconfig"
endmenu
endif

View File

@@ -137,3 +137,5 @@ obj-$(CONFIG_MTD_SPI_NOR) += spi-nor/
obj-$(CONFIG_DOLBY_FW) += dolby_fw/
obj-$(CONFIG_AMLOGIC_PIXEL_PROBE) += pixel_probe/
obj-$(CONFIG_AMLOGIC_FIRMWARE) += firmware/

View File

@@ -0,0 +1,11 @@
# firmware configuration
#
menu "AMLOGIC firmware boot"
config AMLOGIC_FIRMWARE
bool "firmware bootup support"
default n
help
support the amlogic firmware bootup;
endmenu

View File

@@ -0,0 +1,2 @@
obj-$(CONFIG_AMLOGIC_FIRMWARE) += bl40_module.o

View File

@@ -0,0 +1,159 @@
/*
* drivers/amlogic/firmware/bl40_module.c
*
* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
*
* 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.
*
*/
#define pr_fmt(fmt) "bl40: " fmt
#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/io.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/reset.h>
#include <linux/dma-mapping.h>
#include <linux/uaccess.h>
#include <linux/miscdevice.h>
#include <linux/clk.h>
#include <asm/cacheflush.h>
#include <linux/firmware.h>
#include <linux/arm-smccc.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include <linux/of_reserved_mem.h>
#include <linux/amlogic/scpi_protocol.h>
#define AMLOGIC_BL40_BOOTUP 0x8200004E
struct bl40_info {
char name[30];
};
struct device *device;
#define BL40_IOC_MAGIC 'H'
#define BL40_FIRMWARE_LOAD _IOWR(BL40_IOC_MAGIC, 1, struct bl40_info)
static long bl40_miscdev_ioctl(struct file *fp, unsigned int cmd,
unsigned long arg)
{
int ret = 0;
const struct firmware *firmware;
void __user *argp = (void __user *)arg;
struct bl40_info bl40_info;
unsigned long phy_addr;
void *virt_addr = NULL;
struct arm_smccc_res res = {0};
size_t size;
switch (cmd) {
case BL40_FIRMWARE_LOAD:
ret = copy_from_user((void *)&bl40_info,
argp, sizeof(bl40_info));
if (ret < 0)
return ret;
ret = request_firmware(&firmware, bl40_info.name, device);
if (ret < 0) {
pr_err("req firmware fail %d\n", ret);
return ret;
}
size = firmware->size;
virt_addr = devm_kzalloc(device, size, GFP_KERNEL);
if (!virt_addr) {
release_firmware(firmware);
pr_err("memory request fail\n");
return -ENOMEM;
}
memcpy(virt_addr, firmware->data, size);
release_firmware(firmware);
dma_map_single(device, virt_addr, size, DMA_FROM_DEVICE);
phy_addr = virt_to_phys(virt_addr);
/* unlock bl40 */
scpi_unlock_bl40();
arm_smccc_smc(AMLOGIC_BL40_BOOTUP, phy_addr,
size, 0, 0, 0, 0, 0, &res);
pr_info("free memory\n");
devm_kfree(device, virt_addr);
ret = res.a0;
break;
default:
pr_info("Not have this cmd\n");
break;
};
pr_info("bl40 ioctl\n");
return ret;
}
static const struct file_operations bl40_miscdev_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.unlocked_ioctl = bl40_miscdev_ioctl,
.compat_ioctl = bl40_miscdev_ioctl,
};
static struct miscdevice bl40_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "bl40",
.fops = &bl40_miscdev_fops,
};
static int bl40_platform_probe(struct platform_device *pdev)
{
int ret;
device = &pdev->dev;
platform_set_drvdata(pdev, NULL);
ret = misc_register(&bl40_miscdev);
pr_info("bl40 probe\n");
return ret;
}
static int bl40_platform_remove(struct platform_device *pdev)
{
misc_deregister(&bl40_miscdev);
platform_set_drvdata(pdev, NULL);
return 0;
}
static const struct of_device_id bl40_device_id[] = {
{
.compatible = "amlogic, bl40-bootup",
},
{}
};
static struct platform_driver bl40_platform_driver = {
.driver = {
.name = "bl40",
.owner = THIS_MODULE,
.of_match_table = bl40_device_id,
},
.probe = bl40_platform_probe,
.remove = bl40_platform_remove,
};
module_platform_driver(bl40_platform_driver);
MODULE_AUTHOR("Amlogic Bl40");
MODULE_DESCRIPTION("BL40 Boot Module Driver");
MODULE_LICENSE("GPL v2");

View File

@@ -76,6 +76,7 @@ enum scpi_std_cmd {
SCPI_CMD_GET_CEC1 = 0xB4,
SCPI_CMD_GET_CEC2 = 0xB5,
SCPI_CMD_BL4_WAIT_UNLOCK = 0xD6,
SCPI_CMD_COUNT
};
@@ -115,4 +116,5 @@ int scpi_get_cec_val(enum scpi_std_cmd index, u32 *p_cec);
u8 scpi_get_ethernet_calc(void);
int scpi_get_cpuinfo(enum scpi_get_pfm_type type, u32 *freq, u32 *vol);
int scpi_init_dsp_cfg0(u32 id, u32 addr, u32 cfg0);
int scpi_unlock_bl40(void);
#endif /*_SCPI_PROTOCOL_H_*/