From: Samuel Ortiz <sameo@linux.intel.com> To: Lee Jones <lee.jones@linaro.org> Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, linus.walleij@stericsson.com, carriere etienne <etienne.carriere@stericsson.com> Subject: Re: [PATCH 13/26] mfd: ab8500-debugfs: Formated access AB8500 registers from debugfs entry Date: Mon, 28 Jan 2013 00:53:18 +0100 [thread overview] Message-ID: <20130127235318.GQ1174@sortiz-mobl> (raw) In-Reply-To: <1358254566-12419-14-git-send-email-lee.jones@linaro.org> Hi Lee, On Tue, Jan 15, 2013 at 12:55:53PM +0000, Lee Jones wrote: > +static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg, > + struct device *dev) > +{ > + uint write, val = 0; > + struct hwreg_cfg loc = { > + .bank = 0, /* default: invalid phys addr */ > + .addr = 0, /* default: invalid phys addr */ > + .fmt = 0, /* default: 32bit access, hex output */ > + .mask = 0xFFFFFFFF, /* default: no mask */ > + .shift = 0, /* default: no bit shift */ > + }; > + > + /* read or write ? */ > + if (!strncmp(b, "read ", 5)) { > + write = 0; > + b += 5; > + } else if (!strncmp(b, "write ", 6)) { > + write = 1; > + b += 6; > + } else > + return -EINVAL; > + > + /* OPTIONS -l|-w|-b -s -m -o */ > + while ((*b == ' ') || (*b == '-')) { > + if (*(b-1) != ' ') { > + b++; > + continue; > + } > + if ((!strncmp(b, "-d ", 3)) || > + (!strncmp(b, "-dec ", 5))) { > + b += (*(b+2) == ' ') ? 3 : 5; > + loc.fmt |= (1<<0); > + } else if ((!strncmp(b, "-h ", 3)) || > + (!strncmp(b, "-hex ", 5))) { > + b += (*(b+2) == ' ') ? 3 : 5; > + loc.fmt &= ~(1<<0); > + } else if ((!strncmp(b, "-m ", 3)) || > + (!strncmp(b, "-mask ", 6))) { > + b += (*(b+2) == ' ') ? 3 : 6; > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.mask = simple_strtoul(b, &b, 0); > + } else if ((!strncmp(b, "-s ", 3)) || > + (!strncmp(b, "-shift ", 7))) { > + b += (*(b+2) == ' ') ? 3 : 7; > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.shift = simple_strtol(b, &b, 0); > + } else { > + return -EINVAL; > + } > + } > + /* get arg BANK and ADDRESS */ > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.bank = simple_strtoul(b, &b, 0); > + while (*b == ' ') > + b++; > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.addr = simple_strtoul(b, &b, 0); > + > + if (write) { > + while (*b == ' ') > + b++; > + if (strval_len(b) == 0) > + return -EINVAL; > + val = simple_strtoul(b, &b, 0); > + } > + > + /* args are ok, update target cfg (mainly for read) */ > + *cfg = loc; > + > +#if ABB_HWREG_DEBUG > + pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d > + value=0x%X\n", (write) ? "write" : "read", > + REG_FMT_DEC(cfg) ? "decimal" : "hexa", > + cfg->addr, cfg->mask, cfg->shift, val); > +#endif > + > + if (write) { if (!write) return 0; for a more readable code. > + u8 regvalue; > + int ret = abx500_get_register_interruptible(dev, > + (u8)cfg->bank, (u8)cfg->addr, ®value); > + if (ret < 0) { > + dev_err(dev, "abx500_get_reg fail %d, %d\n", > + ret, __LINE__); > + return -EINVAL; > + } > + > + if (cfg->shift >= 0) { > + regvalue &= ~(cfg->mask << (cfg->shift)); > + val = (val & cfg->mask) << (cfg->shift); > + } else { > + regvalue &= ~(cfg->mask >> (-cfg->shift)); > + val = (val & cfg->mask) >> (-cfg->shift); > + } > + val = val | regvalue; > + > + ret = abx500_set_register_interruptible(dev, > + (u8)cfg->bank, (u8)cfg->addr, (u8)val); > + if (ret < 0) { > + pr_err("abx500_set_reg failed %d, %d", ret, __LINE__); > + return -EINVAL; > + } > + > + } > + return 0; > +} I think this is a pretty big routine, that could be split into a command parsing part and the actual register write one. Cheers, Samuel. -- Intel Open Source Technology Centre http://oss.intel.com/
WARNING: multiple messages have this Message-ID (diff)
From: sameo@linux.intel.com (Samuel Ortiz) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 13/26] mfd: ab8500-debugfs: Formated access AB8500 registers from debugfs entry Date: Mon, 28 Jan 2013 00:53:18 +0100 [thread overview] Message-ID: <20130127235318.GQ1174@sortiz-mobl> (raw) In-Reply-To: <1358254566-12419-14-git-send-email-lee.jones@linaro.org> Hi Lee, On Tue, Jan 15, 2013 at 12:55:53PM +0000, Lee Jones wrote: > +static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg, > + struct device *dev) > +{ > + uint write, val = 0; > + struct hwreg_cfg loc = { > + .bank = 0, /* default: invalid phys addr */ > + .addr = 0, /* default: invalid phys addr */ > + .fmt = 0, /* default: 32bit access, hex output */ > + .mask = 0xFFFFFFFF, /* default: no mask */ > + .shift = 0, /* default: no bit shift */ > + }; > + > + /* read or write ? */ > + if (!strncmp(b, "read ", 5)) { > + write = 0; > + b += 5; > + } else if (!strncmp(b, "write ", 6)) { > + write = 1; > + b += 6; > + } else > + return -EINVAL; > + > + /* OPTIONS -l|-w|-b -s -m -o */ > + while ((*b == ' ') || (*b == '-')) { > + if (*(b-1) != ' ') { > + b++; > + continue; > + } > + if ((!strncmp(b, "-d ", 3)) || > + (!strncmp(b, "-dec ", 5))) { > + b += (*(b+2) == ' ') ? 3 : 5; > + loc.fmt |= (1<<0); > + } else if ((!strncmp(b, "-h ", 3)) || > + (!strncmp(b, "-hex ", 5))) { > + b += (*(b+2) == ' ') ? 3 : 5; > + loc.fmt &= ~(1<<0); > + } else if ((!strncmp(b, "-m ", 3)) || > + (!strncmp(b, "-mask ", 6))) { > + b += (*(b+2) == ' ') ? 3 : 6; > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.mask = simple_strtoul(b, &b, 0); > + } else if ((!strncmp(b, "-s ", 3)) || > + (!strncmp(b, "-shift ", 7))) { > + b += (*(b+2) == ' ') ? 3 : 7; > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.shift = simple_strtol(b, &b, 0); > + } else { > + return -EINVAL; > + } > + } > + /* get arg BANK and ADDRESS */ > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.bank = simple_strtoul(b, &b, 0); > + while (*b == ' ') > + b++; > + if (strval_len(b) == 0) > + return -EINVAL; > + loc.addr = simple_strtoul(b, &b, 0); > + > + if (write) { > + while (*b == ' ') > + b++; > + if (strval_len(b) == 0) > + return -EINVAL; > + val = simple_strtoul(b, &b, 0); > + } > + > + /* args are ok, update target cfg (mainly for read) */ > + *cfg = loc; > + > +#if ABB_HWREG_DEBUG > + pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d > + value=0x%X\n", (write) ? "write" : "read", > + REG_FMT_DEC(cfg) ? "decimal" : "hexa", > + cfg->addr, cfg->mask, cfg->shift, val); > +#endif > + > + if (write) { if (!write) return 0; for a more readable code. > + u8 regvalue; > + int ret = abx500_get_register_interruptible(dev, > + (u8)cfg->bank, (u8)cfg->addr, ®value); > + if (ret < 0) { > + dev_err(dev, "abx500_get_reg fail %d, %d\n", > + ret, __LINE__); > + return -EINVAL; > + } > + > + if (cfg->shift >= 0) { > + regvalue &= ~(cfg->mask << (cfg->shift)); > + val = (val & cfg->mask) << (cfg->shift); > + } else { > + regvalue &= ~(cfg->mask >> (-cfg->shift)); > + val = (val & cfg->mask) >> (-cfg->shift); > + } > + val = val | regvalue; > + > + ret = abx500_set_register_interruptible(dev, > + (u8)cfg->bank, (u8)cfg->addr, (u8)val); > + if (ret < 0) { > + pr_err("abx500_set_reg failed %d, %d", ret, __LINE__); > + return -EINVAL; > + } > + > + } > + return 0; > +} I think this is a pretty big routine, that could be split into a command parsing part and the actual register write one. Cheers, Samuel. -- Intel Open Source Technology Centre http://oss.intel.com/
next prev parent reply other threads:[~2013-01-27 23:53 UTC|newest] Thread overview: 110+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-15 12:55 [PATCH 00/26] AB8500 MFD overhaul Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 01/26] mfd: ab8500-sysctrl: Provide a platform specific pm_power_off() call-back Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 02/26] mfd: ab8500-sysctrl: If a charger is present, reboot instead Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:52 ` Samuel Ortiz 2013-01-27 23:52 ` Samuel Ortiz 2013-01-28 8:44 ` Lee Jones 2013-01-28 8:44 ` Lee Jones 2013-01-15 12:55 ` [PATCH 03/26] mfd: ab8500-sysctrl: Only reboot into charging mode if battery type is known Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 04/26] mfd: ab8500-sysctrl.c: Provide charging as reset reason Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 05/26] mfd: ab8500-gpadc: Change to mdelay for greater resolution Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:52 ` Samuel Ortiz 2013-01-27 23:52 ` Samuel Ortiz 2013-01-28 8:43 ` Lee Jones 2013-01-28 8:43 ` Lee Jones 2013-01-15 12:55 ` [PATCH 06/26] mfd: ab8500-sysctrl: Provide configuration for SysClkReqRfClkBuf registers Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:52 ` Samuel Ortiz 2013-01-27 23:52 ` Samuel Ortiz 2013-01-28 8:38 ` Lee Jones 2013-01-28 8:38 ` Lee Jones 2013-02-03 17:02 ` Samuel Ortiz 2013-02-03 17:02 ` Samuel Ortiz 2013-01-15 12:55 ` [PATCH 07/26] mfd: ab8500-sysctrl: export read/write symbols Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 08/26] mfd: abx500-core: Provide an API to dump all ABx500 registers Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 09/26] mfd: ab8500-debugfs: Provide a means for a user subscribe to IRQs Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:52 ` Samuel Ortiz 2013-01-27 23:52 ` Samuel Ortiz 2013-01-28 8:25 ` Lee Jones 2013-01-28 8:25 ` Lee Jones 2013-01-28 10:22 ` Lee Jones 2013-01-28 10:22 ` Lee Jones 2013-01-28 10:49 ` Samuel Ortiz 2013-01-28 10:49 ` Samuel Ortiz 2013-01-28 11:34 ` Lee Jones 2013-01-28 11:34 ` Lee Jones 2013-02-03 17:01 ` Samuel Ortiz 2013-02-03 17:01 ` Samuel Ortiz 2013-02-04 9:27 ` Lee Jones 2013-02-04 9:27 ` Lee Jones 2013-01-15 12:55 ` [PATCH 10/26] mfd: ab8500-debugfs: Wake-up device on debugfs IRQ Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:53 ` Samuel Ortiz 2013-01-27 23:53 ` Samuel Ortiz 2013-01-28 8:49 ` Lee Jones 2013-01-28 8:49 ` Lee Jones 2013-01-15 12:55 ` [PATCH 11/26] mfd: ab8500-debugfs: Keep count of IRQs in debugfs Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 12/26] mfd: ab8500-debugfs: Use NULL to initialise remaining NULL pointer Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 13:06 ` Mark Brown 2013-01-15 13:06 ` Mark Brown 2013-01-15 13:49 ` Lee Jones 2013-01-15 13:49 ` Lee Jones 2013-01-15 12:55 ` [PATCH 13/26] mfd: ab8500-debugfs: Formated access AB8500 registers from debugfs entry Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:53 ` Samuel Ortiz [this message] 2013-01-27 23:53 ` Samuel Ortiz 2013-01-28 8:47 ` Lee Jones 2013-01-28 8:47 ` Lee Jones 2013-01-15 12:55 ` [PATCH 14/26] mfd: ab8500-debugfs: Fix introduced compiler time warnings Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-27 23:53 ` Samuel Ortiz 2013-01-27 23:53 ` Samuel Ortiz 2013-01-28 8:45 ` Lee Jones 2013-01-28 8:45 ` Lee Jones 2013-01-15 12:55 ` [PATCH 15/26] mfd: ab8500-debugfs: Export all AB8500 ADCs as debugfs nodes Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 16/26] mfd: ab8500-debugfs: Set the USB charging current to 300mA for ABV3 Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 17/26] mfd: ab8500-debugfs: add debugfs node to read all registers Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 18/26] mfd: ab8500-core: Allow the possibility to dump all AB8500 registers Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:55 ` [PATCH 19/26] mfd: ab8500-debugfs: Allow number of IRQs to be provided more dynamically Lee Jones 2013-01-15 12:55 ` Lee Jones 2013-01-15 12:56 ` [PATCH 20/26] mfd ab8500-gpadc: Introduce new AB version detection Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-15 12:56 ` [PATCH 21/26] mfd: ab8500-debugfs: Add interrupt debug Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-15 12:56 ` [PATCH 22/26] mfd: ab8500-gpadc: Add runtime pm support Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-15 12:56 ` [PATCH 23/26] mfd: ab8500-pwm: Enable support for AB8505 PWMLED blink Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-27 23:53 ` Samuel Ortiz 2013-01-27 23:53 ` Samuel Ortiz 2013-01-28 8:13 ` Lee Jones 2013-01-28 8:13 ` Lee Jones 2013-01-15 12:56 ` [PATCH 24/26] mfd: ab8500-debugfs: sizeof() mismatch bugfix Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-15 12:56 ` [PATCH 25/26] mfd: ab8500-gpadc: Reduce conversion timeout Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-27 23:53 ` Samuel Ortiz 2013-01-27 23:53 ` Samuel Ortiz 2013-01-28 8:45 ` Lee Jones 2013-01-28 8:45 ` Lee Jones 2013-01-15 12:56 ` [PATCH 26/26] mfd: ab8500-gpadc: Use new ab8500_gpadc_get() with name parameter Lee Jones 2013-01-15 12:56 ` Lee Jones 2013-01-27 23:54 ` Samuel Ortiz 2013-01-27 23:54 ` Samuel Ortiz 2013-01-28 8:11 ` Lee Jones 2013-01-28 8:11 ` Lee Jones
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20130127235318.GQ1174@sortiz-mobl \ --to=sameo@linux.intel.com \ --cc=arnd@arndb.de \ --cc=etienne.carriere@stericsson.com \ --cc=lee.jones@linaro.org \ --cc=linus.walleij@stericsson.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.