On 07/04/16 20:48, Peter Meerwald-Stadler wrote:
Mostly fine, but a few corners need cleaning up.
This just adds support for reporting illuminance with default settings.
All default registers are written on probe because the device otherwise
lacks a reset function.
comments below
Also, I'm not keep on the brute force write everything. The driver should
cope with any values in those registers and deal with refreshing the
cache etc so that it can do so. Writing a bunch of defaults is rather a
brittle approach.
This client pointer isn't used outside probe and remove where it is easily+struct max44000_data {
+ struct mutex lock;
+ struct i2c_client *client;
available anyway. Hence don't keep a copy in here.
See above. This is a really nasty and hard to review way of doing this.+static bool max44000_readable_reg(struct device *dev, unsigned int reg)
+{
+ return (1 << reg) & MAX44000_REGMASK_READABLE;
switch (reg) {
REG1:
REG2:
REG3:
return true;
default:
return false;
may be more code, but it's easy to tell if it is right.
Multiline comment syntax please.+static const struct reg_default max44000_reg_defaults[] = {
+ { MAX44000_REG_CFG_MAIN, 0x24 },
+ /* Upper 4 bits are not documented but start as 1 on powerup
This always seems like a good idea, but tends to cause issues.+ .use_single_rw = 1,
+ .cache_type = REGCACHE_FLAT,
FLAT is really only meant for very high performance devices, you
are probably better with something else here. If you are doing this
deliberately to make the below writes actually occur, then please
add a comment here.
Silly question, but if the cached value matches the values you are trying+static int max44000_force_write_defaults(struct max44000_data *data)
+{
+ int i, ret;
+
+ for (i = 0; i < ARRAY_SIZE(max44000_reg_defaults); ++i) {
+ ret = regmap_write(data->regmap,
+ max44000_reg_defaults[i].reg,
+ max44000_reg_defaults[i].def);
to write here will this work?
There is a regcache_mark_dirty call that will ensure all registers in the
cache are read..
If you then need any particular values they should be explicitly written
on the assumption you have no idea what the state is. Brute force writing
all the defaults is nasty and doesn't give any information as to what
is happening.