Skip to content

sensor sc3336驱动bug #355

@lzjie-tchip

Description

@lzjie-tchip

kernel-6.1调试发现如果没有扫描到i2c id而进入__sc3336_power_off时会发生报错:

[    2.394164] sc3336 4-0030: driver version: 00.01.01
[    2.394254] sc3336 4-0030: could not get default pinstate
[    2.394260] sc3336 4-0030: could not get sleep pinstate
[    2.394286] sc3336 4-0030: supply avdd not found, using dummy regulator
[    2.394356] sc3336 4-0030: supply dovdd not found, using dummy regulator
[    2.394386] sc3336 4-0030: supply dvdd not found, using dummy regulator
[    2.396719] mmc_host mmc1: Bus speed (slot 0) = 400000Hz (slot req 400000Hz, actual 400000HZ div = 0)
[    2.402530] sc3336 4-0030: Unexpected sensor id(000000), ret(-5)
[    2.402556] ------------[ cut here ]------------
[    2.402560] WARNING: CPU: 5 PID: 1 at drivers/regulator/core.c:2411 _regulator_put.part.0+0x158/0x160
[    2.402572] Modules linked in:
[    2.402577] CPU: 5 PID: 1 Comm: swapper/0 Not tainted 6.1.84 #179
[    2.402583] Hardware name: Firefly EXT-iCore-3576Q38 Linux (DT)
[    2.402587] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[    2.402592] pc : _regulator_put.part.0+0x158/0x160
[    2.402597] lr : regulator_bulk_free+0x64/0x8c
[    2.402601] sp : ffffffc00afbbac0
[    2.402605] x29: ffffffc00afbbac0 x28: 0000000000000000 x27: ffffffc00a1c00c8
[    2.402613] x26: ffffffc00a2a6060 x25: 0000000000000006 x24: 0000000000000006
[    2.402620] x23: ffffffc009e7ec10 x22: ffffff80c1180910 x21: ffffffc00ac1f050
[    2.402627] x20: ffffff80c0a51300 x19: ffffff80c0a51300 x18: 0000000000000030
[    2.402633] x17: 28746572202c2930 x16: 3030303030286469 x15: ffffffffffffffff
[    2.402640] x14: 0000000000000000 x13: 29352d2874657220 x12: 2c29303030303030
[    2.402646] x11: 0000000000000001 x10: ffffff80c11ad1a8 x9 : ffffffc0088a6548
[    2.402653] x8 : ffffffc008afcf50 x7 : ffffff80c11ad1a8 x6 : ffffff80c11ad1a8
[    2.402660] x5 : ffffffc008afe8ec x4 : fffffffe03046b60 x3 : 0000000000000000
[    2.402666] x2 : ffffff80c0358000 x1 : 0000000000000000 x0 : 0000000000000001
[    2.402673] Call trace:
[    2.402677]  _regulator_put.part.0+0x158/0x160
[    2.402682]  regulator_bulk_free+0x64/0x8c
[    2.402687]  devm_regulator_bulk_release+0x20/0x30
[    2.402693]  devres_release_group+0x120/0x1f4
[    2.402698]  i2c_device_probe+0x138/0x350
[    2.402705]  really_probe+0xc4/0x3e0
[    2.402711]  __driver_probe_device+0x80/0x160
[    2.402717]  driver_probe_device+0x40/0x110
[    2.402722]  __driver_attach+0xec/0x1f0
[    2.402727]  bus_for_each_dev+0x74/0xd0
[    2.402732]  driver_attach+0x28/0x30
[    2.402737]  bus_add_driver+0x178/0x234
[    2.402742]  driver_register+0x7c/0x130
[    2.402747]  i2c_register_driver+0x4c/0xec
[    2.402753]  sensor_mod_init+0x20/0x28
[    2.402759]  do_one_initcall+0x48/0x250
[    2.402764]  kernel_init_freeable+0x298/0x304
[    2.402772]  kernel_init+0x28/0x12c
[    2.402776]  ret_from_fork+0x10/0x20

原因是执行了两次clk_disable_unprepare,需要把第二次重复的去掉:

static void __sc3336_power_off(struct sc3336 *sc3336)
{
        int ret;
        struct device *dev = &sc3336->client->dev;

        clk_disable_unprepare(sc3336->xvclk);
        if (sc3336->is_thunderboot) {
                if (sc3336->is_first_streamoff) {
                        sc3336->is_thunderboot = false;
                        sc3336->is_first_streamoff = false;
                } else {
                        return;
                }
        }

        if (!IS_ERR(sc3336->pwdn_gpio))
                gpiod_set_value_cansleep(sc3336->pwdn_gpio, 0);
        //clk_disable_unprepare(sc3336->xvclk);
        if (!IS_ERR(sc3336->reset_gpio))
                gpiod_set_value_cansleep(sc3336->reset_gpio, 0);
        if (!IS_ERR_OR_NULL(sc3336->pins_sleep)) {
                ret = pinctrl_select_state(sc3336->pinctrl,
                                           sc3336->pins_sleep);
                if (ret < 0)
                        dev_dbg(dev, "could not set pins\n");
        }
        regulator_bulk_disable(SC3336_NUM_SUPPLIES, sc3336->supplies);
}

sc3336p疑似也可能有类似问题

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions