misc: Import mmhardware detection
From branch: redwood-s-oss Change-Id: I03d8e19d51e7519abb57450a67a18031f727529d
This commit is contained in:
parent
82656adb96
commit
2ccd7dec94
@ -530,6 +530,12 @@ config MI_HARDWARE_ID
|
||||
help
|
||||
This adds support for mi hwid.
|
||||
|
||||
config MMHARDWARE_OTHER_DETECTION
|
||||
tristate "Register xiaomi mmhardware detection module"
|
||||
default m
|
||||
help
|
||||
This adds support for mmhardware detection
|
||||
|
||||
source "drivers/misc/c2port/Kconfig"
|
||||
source "drivers/misc/eeprom/Kconfig"
|
||||
source "drivers/misc/cb710/Kconfig"
|
||||
|
@ -67,3 +67,4 @@ obj-$(CONFIG_WIGIG_SENSING_SPI) += wigig_sensing.o
|
||||
obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
|
||||
obj-$(CONFIG_MI_HARDWARE_ID) += hwid.o
|
||||
obj-$(CONFIG_ISPV2_AL6021) += al6021/
|
||||
obj-$(CONFIG_MMHARDWARE_OTHER_DETECTION) += mmhardware_others.o
|
||||
|
133
drivers/misc/mmhardware_others.c
Normal file
133
drivers/misc/mmhardware_others.c
Normal file
@ -0,0 +1,133 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/mmhardware_others.h>
|
||||
|
||||
/* show */
|
||||
static ssize_t mm_register_show(struct kobject *dev,
|
||||
struct kobj_attribute *a, char *buf)
|
||||
{
|
||||
struct mm_info *mi = container_of(a, struct mm_info, k_attr);
|
||||
|
||||
switch (mi->mm_id) {
|
||||
case MM_HW_HAPTIC_1:
|
||||
if (!mi->on_register) {
|
||||
pr_info("%s: 0x%x is not registered\n", __func__, mi->mm_id);
|
||||
}
|
||||
return sprintf(buf, "%d\n", mi->on_register);
|
||||
break;
|
||||
case MM_HW_HAPTIC_2:
|
||||
if (!mi->on_register) {
|
||||
pr_info("%s: 0x%x is not registered\n", __func__, mi->mm_id);
|
||||
}
|
||||
return sprintf(buf, "%d\n", mi->on_register);
|
||||
break;
|
||||
case MM_HW_AS:
|
||||
if (!mi->on_register) {
|
||||
pr_info("%s: 0x%x is not registered\n", __func__, mi->mm_id);
|
||||
}
|
||||
return sprintf(buf, "%d\n", mi->on_register);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* store */
|
||||
static ssize_t mm_register_store(struct kobject *dev,
|
||||
struct kobj_attribute *a, const char *buf, size_t count)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
MM_INFO(MM_HW_HAPTIC_1, haptic1);
|
||||
MM_INFO(MM_HW_HAPTIC_2, haptic2);
|
||||
MM_INFO(MM_HW_AS, audioswitch);
|
||||
|
||||
static struct attribute *mm_attrs[] = {
|
||||
&haptic1_info.k_attr.attr,
|
||||
&haptic2_info.k_attr.attr,
|
||||
&audioswitch_info.k_attr.attr,
|
||||
NULL, /* need to NULL terminate the list of attributes */
|
||||
};
|
||||
|
||||
static struct attribute_group mm_attr_group = {
|
||||
.attrs = mm_attrs,
|
||||
};
|
||||
|
||||
static struct kobject *mm_sysfs_kobj;
|
||||
|
||||
static int __init mmhardware_others_init(void)
|
||||
{
|
||||
int err;
|
||||
/* create mm_hardware under /sys */
|
||||
mm_sysfs_kobj = kobject_create_and_add(MM_HARDWARE_SYSFS_OTHERS_FOLDER, kernel_kobj->parent);
|
||||
if (!mm_sysfs_kobj) {
|
||||
pr_err("failed to create kobj");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = sysfs_create_group(mm_sysfs_kobj, &mm_attr_group);
|
||||
|
||||
if (err) {
|
||||
pr_err("failed to create sysfs group");
|
||||
kobject_put(mm_sysfs_kobj);
|
||||
return -ENOMEM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit mmhardware_others_exit(void)
|
||||
{
|
||||
kobject_put(mm_sysfs_kobj);
|
||||
}
|
||||
|
||||
int register_otherkobj_under_mmsysfs(enum hardware_id mm_id, const char *name)
|
||||
{
|
||||
int ret = 0;
|
||||
int iter = 0;
|
||||
int find_id = 0;
|
||||
struct mm_info *mi = NULL;
|
||||
struct kobj_attribute *mi_attr = NULL;
|
||||
struct attribute *a = mm_attrs[iter];
|
||||
|
||||
if (name == NULL) {
|
||||
pr_err("%s: device_name is empty\n", __func__);
|
||||
ret = -2;
|
||||
goto err;
|
||||
}
|
||||
|
||||
while (a) {
|
||||
mi_attr = container_of(a, struct kobj_attribute, attr);
|
||||
mi = container_of(mi_attr, struct mm_info, k_attr);
|
||||
iter++;
|
||||
a = mm_attrs[iter];
|
||||
if (mm_id == mi->mm_id) {
|
||||
find_id = 1;
|
||||
if (mi->on_register) {
|
||||
pr_info("%s: device(id:%d name:%s) has already registered\n", __func__, mi->mm_id, name);
|
||||
ret = -4;
|
||||
goto err;
|
||||
}
|
||||
mi->on_register = 1;
|
||||
goto err;
|
||||
} else continue;
|
||||
}
|
||||
|
||||
if (find_id == 0) {
|
||||
pr_err("%s: Can't find correct hardware_id: 0x%x\n", __func__, mm_id);
|
||||
ret = -3;
|
||||
}
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(register_otherkobj_under_mmsysfs);
|
||||
|
||||
module_init(mmhardware_others_init);
|
||||
module_exit(mmhardware_others_exit);
|
||||
MODULE_DESCRIPTION("mm module");
|
||||
MODULE_LICENSE("GPL v2");
|
@ -12,6 +12,7 @@
|
||||
#include <linux/usb/ucsi_glink.h>
|
||||
#include <linux/soc/qcom/fsa4480-i2c.h>
|
||||
#include <linux/iio/consumer.h>
|
||||
#include <linux/mmhardware_others.h>
|
||||
|
||||
#define FSA4480_I2C_NAME "fsa4480-driver"
|
||||
|
||||
@ -521,6 +522,9 @@ static int fsa4480_probe(struct i2c_client *i2c,
|
||||
((fsa_priv->fsa4480_notifier).rwsem);
|
||||
fsa_priv->fsa4480_notifier.head = NULL;
|
||||
|
||||
#ifdef CONFIG_MMHARDWARE_OTHER_DETECTION
|
||||
register_otherkobj_under_mmsysfs(MM_HW_AS, "audioswitch");
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
err_supply:
|
||||
|
40
include/linux/mmhardware_others.h
Normal file
40
include/linux/mmhardware_others.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __MMHARDWARE_OTHERS_H__
|
||||
#define __MMHARDWARE_OTHERS_H__
|
||||
|
||||
#define MM_HARDWARE_SYSFS_OTHERS_FOLDER "others"
|
||||
#define MM_HARDWARE_SYSFS_AUDIOSWITCH_FOLDER "audioswitch"
|
||||
#define MM_HARDWARE_SYSFS_HAPTIC_1_FOLDER "haptic1"
|
||||
#define MM_HARDWARE_SYSFS_HAPTIC_2_FOLDER "haptic2"
|
||||
|
||||
enum hardware_id {
|
||||
MM_HW_AS = 0x800,
|
||||
MM_HW_HAPTIC_1 = 0x1000,
|
||||
MM_HW_HAPTIC_2 = 0x2000
|
||||
};
|
||||
|
||||
struct mm_info {
|
||||
struct kobj_attribute k_attr;
|
||||
enum hardware_id mm_id;
|
||||
int on_register;
|
||||
};
|
||||
|
||||
#define __MMHW(_id, _mm_name) { \
|
||||
.k_attr = { \
|
||||
.attr = { \
|
||||
.name = __stringify(_mm_name), \
|
||||
.mode = 0644, \
|
||||
}, \
|
||||
.show = mm_register_show, \
|
||||
.store = mm_register_store, \
|
||||
}, \
|
||||
.mm_id = _id, \
|
||||
.on_register = 0, \
|
||||
}
|
||||
|
||||
/* create sysfs node */
|
||||
#define MM_INFO(_id, _mm_name) \
|
||||
struct mm_info _mm_name##_info = __MMHW(_id, _mm_name)
|
||||
|
||||
int register_otherkobj_under_mmsysfs(enum hardware_id mm_id, const char *name);
|
||||
|
||||
#endif
|
59
include/linux/mmhardware_sysfs.h
Normal file
59
include/linux/mmhardware_sysfs.h
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef __MMHARDWARE_SYSFS_H__
|
||||
#define __MMHARDWARE_SYSFS_H__
|
||||
|
||||
#define MM_HARDWARE_SYSFS_ROOT_FOLDER "mm_hardware"
|
||||
#define MM_HARDWARE_SYSFS_ADSP_FOLDER "adsp"
|
||||
#define MM_HARDWARE_SYSFS_CODEC_FOLDER "codec"
|
||||
#define MM_HARDWARE_SYSFS_PA_1_FOLDER "pa1"
|
||||
#define MM_HARDWARE_SYSFS_PA_2_FOLDER "pa2"
|
||||
#define MM_HARDWARE_SYSFS_PA_3_FOLDER "pa3"
|
||||
#define MM_HARDWARE_SYSFS_PA_4_FOLDER "pa4"
|
||||
#define MM_HARDWARE_SYSFS_PA_5_FOLDER "pa5"
|
||||
#define MM_HARDWARE_SYSFS_PA_6_FOLDER "pa6"
|
||||
#define MM_HARDWARE_SYSFS_PA_7_FOLDER "pa7"
|
||||
#define MM_HARDWARE_SYSFS_PA_8_FOLDER "pa8"
|
||||
|
||||
enum hardware_id {
|
||||
MM_HW_FINE = 0x1,
|
||||
MM_HW_ADSP = 0x2,
|
||||
MM_HW_CODEC = 0x4,
|
||||
MM_HW_PA_1 = 0x8,
|
||||
MM_HW_PA_2 = 0x10,
|
||||
MM_HW_PA_3 = 0x20,
|
||||
MM_HW_PA_4 = 0x40,
|
||||
MM_HW_PA_5 = 0x80,
|
||||
MM_HW_PA_6 = 0x100,
|
||||
MM_HW_PA_7 = 0x200,
|
||||
MM_HW_PA_8 = 0x400
|
||||
};
|
||||
|
||||
struct mm_info {
|
||||
struct kobj_attribute k_attr;
|
||||
enum hardware_id mm_id;
|
||||
int on_register;
|
||||
int on_calibration;
|
||||
};
|
||||
|
||||
#define __MMHW(_id, _mm_name) { \
|
||||
.k_attr = { \
|
||||
.attr = { \
|
||||
.name = __stringify(_mm_name), \
|
||||
.mode = 0644, \
|
||||
}, \
|
||||
.show = mm_register_show, \
|
||||
.store = mm_register_store, \
|
||||
}, \
|
||||
.mm_id = _id, \
|
||||
.on_register = 0, \
|
||||
.on_calibration = 0, \
|
||||
}
|
||||
|
||||
/* create sysfs node */
|
||||
#define MM_INFO(_id, _mm_name) \
|
||||
struct mm_info _mm_name##_info = __MMHW(_id, _mm_name)
|
||||
|
||||
int mmhardware_initialize_sysfs(void);
|
||||
void mmhardware_cleanup_sysfs(void);
|
||||
int register_kobj_under_mmsysfs(enum hardware_id mm_id, const char *name);
|
||||
int on_calibration_under_mmsysfs(enum hardware_id mm_id, const char *name);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user