debug code example in Kernel
2014-04-10 11:01
295 查看
debug备忘
========================================= 1 ============================================
static ssize_t led_store_debug_mode(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
sscanf(buf, "%d", &debug_mode);
pr_info("leds-qpnp: %s debug mode\n",
debug_mode ? "enabling" : "disabling");
return count;
}
static ssize_t led_show_debug_mode(struct device *dev,
struct device_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE, "%d\n", debug_mode);
}
static DEVICE_ATTR(debug_mode, 0644, led_show_debug_mode, led_store_debug_mode);
static int __devinit qpnp_leds_probe(struct spmi_device *spmi)
{
rc = device_create_file(led->cdev.dev, &dev_attr_debug_mode);
if (rc)
device_remove_file(led->cdev.dev, &dev_attr_debug_mode);
break;
}
========================================= 2 ============================================
static ssize_t led_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct qpnp_led_data *led;
unsigned long state;
struct led_classdev *led_cdev = dev_get_drvdata(dev);
ssize_t ret = -EINVAL;
ret = kstrtoul(buf, 10, &state);
if (ret)
return ret;
led = container_of(led_cdev, struct qpnp_led_data, cdev);
return count;
}
static ssize_t led_strobe_type_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct qpnp_led_data *led;
unsigned long state;
struct led_classdev *led_cdev = dev_get_drvdata(dev);
ssize_t ret = -EINVAL;
ret = kstrtoul(buf, 10, &state);
if (ret)
return ret;
led = container_of(led_cdev, struct qpnp_led_data, cdev);
return count;
}
static DEVICE_ATTR(led_mode, 0664, NULL, led_mode_store);
static DEVICE_ATTR(strobe, 0664, NULL, led_strobe_type_store);
static struct attribute *led_attrs[] = {
&dev_attr_led_mode.attr,
&dev_attr_strobe.attr,
NULL
};
static const struct attribute_group led_attr_group = {
.attrs = led_attrs,
};
static int __devinit qpnp_leds_probe(struct spmi_device *spmi)
{
rc = sysfs_create_group(&led->cdev.dev->kobj,
&led_attr_group);
}
static int __devexit qpnp_leds_remove(struct spmi_device *spmi)
{
sysfs_remove_group(&led_array[i].cdev.dev->kobj,
&led_attr_group);
break;
}
========================================= 3 ============================================
#if DEBUG_FLASH_CN
static int foo = 0;
static struct kobject *flash_kobj;
struct qpnp_led_data *flash_debug_led;
static ssize_t flash_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf) //cat
{
foo++;
pr_err("+++++ flash %s(ID: %d) +++++ \n", __func__, foo);
qpnp_dump_regs(flash_debug_led, flash_debug_regs, ARRAY_SIZE(flash_debug_regs));
pr_err("- - - - - - - - - - - - - - \n");
qpnp_dump_regs_2(flash_debug_led);
pr_err("----- flash %s(ID: %d) ----- \n", __func__, foo);
return sprintf(buf, "%d\n", foo);
}
static ssize_t flash_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count) //echo >
{
u8 val;
sscanf(buf, "%d", &foo);
pr_err("foo = %d.\n",foo);
pr_err("flash %s()++++ \n", __func__);
qpnp_dump_regs(flash_debug_led, flash_debug_regs, ARRAY_SIZE(flash_debug_regs));
pr_err("%s(), rewrite some registers start \n", __func__);
spmi_ext_register_readl(flash_debug_led->spmi_dev->ctrl, flash_debug_led->spmi_dev->sid, 0xd352, &val, sizeof(val));
pr_err("%s(), rewrite reg0xd352=0x%x to 0x%x.\n", __func__, val, val&0x7F);
val &= 0x7F;
spmi_ext_register_writel(flash_debug_led->spmi_dev->ctrl, flash_debug_led->spmi_dev->sid, 0xd352, &val, sizeof(val));
pr_err("%s(), rewrite some registers end \n", __func__);
return count;
}
static struct kobj_attribute flash_attribute =
__ATTR(fd_node, 0666, flash_show, flash_store);
/*
* Create a group of attributes so that we can create and destroy them all
* at once.
*/
static struct attribute *attrs[] = {
&flash_attribute.attr,
NULL, /* need to NULL terminate the list of attributes */
};
/*
* An unnamed attribute group will put all of the attributes directly in
* the kobject directory. If we specify a name, a subdirectory will be
* created for the attributes with the directory being the name of the
* attribute group.
*/
static struct attribute_group flash_attr_group = {
.attrs = attrs,
};
static int __devinit qpnp_leds_probe(struct spmi_device *spmi)
{
#if DEBUG_FLASH_CN
/*
* Create a simple kobject with the name of "flash_debug",
* located under /sys/kernel/
*
* As this is a simple directory, no uevent will be sent to
* userspace. That is why this function should not be used for
* any type of dynamic kobjects, where the name and number are
* not known ahead of time.
*/
sprintf(flash_debug_dir, "flash_debug%d", led->id);
pr_err("[CNYL]: create flash(%d) debug node start!\n", led->id);
flash_kobj = kobject_create_and_add(flash_debug_dir, kernel_kobj);
if (!flash_kobj)
return -ENOMEM;
/* Create the files associated with this kobject */
retval = sysfs_create_group(flash_kobj, &flash_attr_group);
if (retval) {
kobject_put(flash_kobj);
pr_err("[CNYL]: create flash debug node failed.\n");
}
flash_debug_led = led;
pr_err("[CNYL]: create flash(%d) debug node done!\n", led->id);
#endif
}
========================================= 4 ============================================
diff --git a/drivers/media/platform/msm/camera_v2/sensor/ar0543.c b/drivers/media/platform/msm/camera_v2/sensor/ar0543.c
index abaa4bd..e22d0f1 100755
--- a/drivers/media/platform/msm/camera_v2/sensor/ar0543.c
+++ b/drivers/media/platform/msm/camera_v2/sensor/ar0543.c
@@ -16,6 +16,8 @@
#define AR0543_SENSOR_NAME "ar0543"
DEFINE_MSM_MUTEX(ar0543_mut);
+#define SENSOR_KERNEL_DEBUG 1
+
static struct msm_sensor_ctrl_t ar0543_s_ctrl;
static struct msm_sensor_power_setting ar0543_power_setting[] = {
@@ -145,6 +147,108 @@ static struct platform_driver ar0543_platform_driver = {
},
};
+#if SENSOR_KERNEL_DEBUG
+static struct msm_camera_i2c_reg_array reg_w;
+static ssize_t sensor_status_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ ssize_t length = 0;
+ length = sprintf(buf, "sensor reg dump:\n"
+ " random read,addr-value:0x%04x - 0x%04x.%s\n",
+ reg_w.reg_addr, reg_w.reg_data,
+ (reg_w.reg_data != 0) ? " " : " (Have you read already?)"
+ );
+/*
+ length = sprintf(buf, "debug Information(version: 20131030):\n"
+ "[R] command: reset the following parameters.\n"
+ "[s] msleep_time:\t%dms (effect in each AF/CAF).\n"
+ "[i] step_interval:\t%d (effect in opening camera).\n"
+ "[l/h] focuser range:\t%d--%d.\n"
+ "[f] flag_debug_foc:\t%d (%s).\n"
+ "[p] set_lens_pos:\t%d (enc_set:0x%x, enc_check:0x%x, diff: 0x%x).\n",
+ tinfo.msleep_time,
+ tinfo.step_interval,
+ tinfo.pos_low, tinfo.pos_high,
+ tinfo.flag_debug_foc, tinfo.flag_debug_foc ? "Debug Mode" : "Normal Mode",
+ tinfo.set_lens_pos, tinfo.enc_set_lens_pos, tinfo.enc_actual_lens_pos, abs_closeloop(tinfo.enc_set_lens_pos-tinfo.enc_actual_lens_pos)
+ );
+*/
+ return length;
+}
+
+
+static ssize_t sensor_attr_set(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ int err;
+ const char *ptr = buf + 1;
+ //u8 ch;
+ //size_t idx = 0;
+ //u32 val = 0;
+ char reg_buf[7], data_buf[7];
+
+ *(reg_buf + 6) = '\0';
+ *(data_buf + 6) = '\0';
+
+ if (count <= 1)
+ return count;
+
+ if (ptr) {
+ switch (buf[0]) {
+ case 'R':
+ break;
+ case 'w'://format: w0xABCD,0xEFGH
+ //if (count <= 1)
+ //return count;
+ memcpy(reg_buf, (buf + 1), 6);
+ memcpy(data_buf, (buf + 8), 6);
+ reg_w.reg_addr = (unsigned short)simple_strtoul(reg_buf, NULL, 16);
+ reg_w.reg_data = (unsigned short)simple_strtoul(data_buf, NULL, 16);
+ pr_info("SENSOR write{0x%04X, 0x%04X}.\n", reg_w.reg_addr, reg_w.reg_data);
+ err = ar0543_s_ctrl.sensor_i2c_client->i2c_func_tbl->i2c_write(ar0543_s_ctrl.sensor_i2c_client, reg_w.reg_addr, reg_w.reg_data, MSM_CAMERA_I2C_WORD_DATA);
+ reg_w.reg_data = 0;
+ if (err)
+ return err;
+ break;
+ case 'r'://format: r0xABCD
+ //if (count <= 1)
+ //return count;
+ memcpy(reg_buf, (buf + 1), 6);
+ reg_w.reg_addr = (unsigned short)simple_strtoul(reg_buf, NULL, 16);
+ pr_info("SENSOR read{0x%04X}.\n", reg_w.reg_addr);
+ err = ar0543_s_ctrl.sensor_i2c_client->i2c_func_tbl->i2c_read(ar0543_s_ctrl.sensor_i2c_client, reg_w.reg_addr, &(reg_w.reg_data), MSM_CAMERA_I2C_WORD_DATA);
+ if (err)
+ return err;
+ break;
+ }
+ }
+
+ return count;
+}
+
+static DEVICE_ATTR(d, 0775, sensor_status_show, sensor_attr_set);
+struct kobject *keobj;
+
+static int drv_sensor_sysfs_init(void /*struct test_info_t *info*/)
+{
+ keobj = kobject_create_and_add("sensor", NULL);
+ if (!keobj) {
+ pr_err("%s subsystem register failed!\n", __func__);
+ return -ENOMEM;
+ }
+
+ if (sysfs_create_file(keobj, &dev_attr_d.attr)) {
+ pr_err("%s sysfs create file failed!\n", __func__);
+ kobject_del(keobj);
+ keobj = NULL;
+ return -ENOMEM;
+ }
+ //ker_info = info;
+
+ return 0;
+}
+#endif
+
static int32_t ar0543_platform_probe(struct platform_device *pdev)
{
int32_t rc = 0;
@@ -152,6 +256,11 @@ static int32_t ar0543_platform_probe(struct platform_device *pdev)
match = of_match_device(ar0543_dt_match, &pdev->dev);
rc = msm_sensor_platform_probe(pdev, match->data);
+
+#if SENSOR_KERNEL_DEBUG
+ drv_sensor_sysfs_init();
+#endif
+
return rc;
}
相关文章推荐
- Tree in Combo Box example code (using HTTPService and XML)
- PHP学习笔记 - 在Eclipse中使用XDebug调试代码 | Using XDebug debug code in eclipse
- inline code debug assistance on ReflectionTypeL...
- Debug a NIC driver in linux(kernel version 2.4.20-8) which running on VMware workstation version 4.5.2
- Example Code of Using XML Parser in Symbian OS
- TCP Socket Establish;UDP Send Package Process In Kernel Sourcecode Learning
- Pseudo code for In-class QuestionExample 3: Write pseudo code that performs the following: Ask a use
- Walkthrough:SPSiteDataQuery example code in C#
- A general messagebox src code paragraph for debug in Gtk+ programming
- how to install your kernel code in FC6
- How to Debug Enterprise Portal Code in Dynamics AX 2009
- How to compile and debug VLC player source code in eclipse IDE on Ubuntu 10.04 (lucid)?
- Design Patterns Example Code (in C++)
- How to do live debug the Managed code in Windows Phone 7
- CPU frequency and voltage scaling code in the Linux(TM) kernel
- Deleting a Mounted Folder The code example in this topic shows you how to delete a mounted folder by
- How to collect TrustZone debug logs and check the meaning of error code in the logs
- Example code of searching in WordNet Dictionary with JAWS library
- Debug Source Code in .NET Framework (跟踪 debug .net 底层 dll)
- CPU frequency and voltage scaling code in the Linux(TM) kernel