Commit Graph

562 Commits

Author SHA1 Message Date
macallan
d33396435d match "i2c-at34c02", found in various sparc64 boxes 2018-10-20 03:23:05 +00:00
jmcneill
f689fd3cfe lock/unlock I2C bus around transfers as required by API 2018-10-17 16:56:40 +00:00
bouyer
704a6a18c7 Expand code covered by sc->sc_mtx, to make sure an interrupt would not be
handled before the cv_timedwait_sig() call, or while polling.
Seems to fix "sunxitwi0: send STOP failed" messages frequently seen related
to axp20x0 sensors.
2018-10-01 09:39:20 +00:00
jakllsch
7079c61c32 match spdmem_i2c on "atmel,spd" compatible string 2018-09-26 20:15:08 +00:00
jmcneill
7eaa7ef21d Add support for RK805 2018-09-20 09:02:46 +00:00
riastradh
d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
jmcneill
35517e5ce1 Add driver for Rockchip RK808 Power Management IC. 2018-09-02 01:16:58 +00:00
jmcneill
8a2d1497e7 Initialize transition slew rate if specified in the DT 2018-08-29 11:08:30 +00:00
jmcneill
a61e0fbcba Add driver for Silergy SY827/SY828 step down regulator. 2018-08-29 01:57:38 +00:00
rkujawa
214d4ae2ac Add TEA5767 FM radio driver. From Karuna Grewal. 2018-07-27 12:02:25 +00:00
macallan
da2ab6d431 fix a tpyo so now we get the correct maximum speed for CPU intake fans
while there, be a bit more responsive to temperature changes
2018-06-28 21:21:03 +00:00
thorpej
067d2463e3 Remove the i2c "size" locator and corresponding property / attach arg.
It was a hack meant only for EEPROMs, which have another way to specify
size in the config directive ("flag" paramter), as well as a better way
to detect size based on "compatible" string.
2018-06-26 06:34:55 +00:00
thorpej
7b7b75dcdf Encode the size information in the compat data. 2018-06-26 06:21:23 +00:00
thorpej
feee3a19f4 In my quest to make device_compatible_entry (and associated goo)
super-general, it turns out I also made it a little to cumbersome
to use (if my tired fingers are any indication).  So, this is a
course-correction -- one string per entry (like of_compat_data,
which it will soon replace), and remove the over-verbose macros.
2018-06-26 06:03:57 +00:00
thorpej
408f5aa571 Change device_compatible_match() and iic_compatible_match() to return
the weighted match value and take an optional compatible-entry pointer,
rather than the other way around.
2018-06-26 04:32:35 +00:00
martin
d12ff78ef9 iic_use_direct_match(): when iic_compatible_match() does not find a
comptible entry, set match quality to 0. Otherwise callers might use
random stack garbage.
2018-06-22 15:52:00 +00:00
martin
065c050ee0 Add a kernel panic when we matched but can not handle a string - better
die explicitly instead of crashing a few lines later with strange NULL
derefs.
2018-06-22 15:48:57 +00:00
thorpej
4081e2be7c Use the device_compatible_entry mechanism rather than of_compat_data;
all of the OF / FDT data we need is already in the i2c_attach_args.
2018-06-19 02:08:12 +00:00
thorpej
4f9e5a443e - Rename iic_compat_match() to iic_compatible_match() and change it
to use the new device_compatible_match() routine.  A pointer to
  the matching device_compatible_entry is returned if a match is
  found.
- Adjust iic_use_direct_match() accordingly.
- i2c drivers now provide device_compatible_entry tables when performing
  direct-config matching.
- In the dsrtc driver, take advantage of this new capability to greatly
  simplify model selection.

(I'm coming for you next, of_compat_data...)
2018-06-18 17:07:07 +00:00
jakllsch
aaa141ed7e Bail early if gttwsi_send_start() fails in gttwsi_initiate_xfer() to
avoid unexpected state error message later (on Allwinner H5).
2018-06-18 12:42:29 +00:00
thorpej
6ffcc72460 Fix compilation error pointed out by nishimura@. 2018-06-17 14:50:54 +00:00
thorpej
1de0c2e2c3 Oops, another one. 2018-06-17 01:08:15 +00:00
thorpej
81d957210f Remove now-unused variable. 2018-06-17 01:07:06 +00:00
thorpej
6f3ab6bd89 More cleanup to i2c autoconfiguration:
- Get all of the drivers onto the new match quality constants.
- Introduce a new helper function, iic_use_direct_match(), that has
  all of the logic for direct-config matching.  If it returns true,
  the driver returns the match result (which may be 0).  If it returns
  false, the driver does indirect-config matching.
- iic_compat_match() now returns a weighted match quality; matches to
  lower-indexed "compatible" device property are more-specific matches,
  and return a better match quality accordingly.

In addition to the above:
- Add support for direct-config matching this driver based on
  "compatible" properties.
- Address-only matching is now done based on the specific addresses
  the requested model supports.
- "compatible" property can specify to the driver which model is to
  be used, so that using config "flags" directives aren't required
  in the direct-config case.

XXX More changes coming that require re-factoring some other code.
2018-06-16 21:28:07 +00:00
thorpej
23a4765aee More cleanup to i2c autoconfiguration:
- Get all of the drivers onto the new match quality constants.
- Introduce a new helper function, iic_use_direct_match(), that has
  all of the logic for direct-config matching.  If it returns true,
  the driver returns the match result (which may be 0).  If it returns
  false, the driver does indirect-config matching.
- iic_compat_match() now returns a weighted match quality; matches to
  lower-indexed "compatible" device property are more-specific matches,
  and return a better match quality accordingly.

XXX This driver is an odd-ball with respect to the hardware device.
See comments in the match routine.  Unclear how best to handle it.
2018-06-16 21:24:36 +00:00
thorpej
aa41e9922c More cleanup to i2c autoconfiguration:
- Get all of the drivers onto the new match quality constants.
- Introduce a new helper function, iic_use_direct_match(), that has
  all of the logic for direct-config matching.  If it returns true,
  the driver returns the match result (which may be 0).  If it returns
  false, the driver does indirect-config matching.
- iic_compat_match() now returns a weighted match quality; matches to
  lower-indexed "compatible" device property are more-specific matches,
  and return a better match quality accordingly.
2018-06-16 21:22:13 +00:00
thorpej
e4ede69598 When initiating a transfer, if a device isn't present, we won't
get an ACK after sending the address.  Check for this alternate
state and suppress the error message when it occurs.

Fixes PR kern/53356.
2018-06-12 13:18:48 +00:00
thorpej
ec79b37bf9 Changes / enhancements to i2c indirect device auto-configuration:
— iic_search() chooses a “probe strategy” based on the
  "i2c-indirect-probe-strategy” property on the “iic” instance.
  Valid values are "smbus-quick-write”, "smbus-receive-byte”, and
  “none”.  If no value is specified, the default is "smbus-quick-write”.

— If the "i2c-indirect-device-whitelist” exists on the “iic” instance,
  iic_search() will first check the driver name in the cfdata_t against
  this list, and only allow the match/probe to move forward if the
  cfdata_t driver name is in the list.  This is primarily to accommodate
  the Intel integrated memory controller neutered-i2c-thing.

— If the cfdata_t specifies a wildcard address, each address of the i2c
  bus will be consulted.  If the cfdata_t contains a nailed-down address,
  then we limit the bus scan to that specific address.

— We explicitly skip reserved / special i2c addresses, such as the
  General-Call address, etc.

— We introduce the notion of a “match quality” for i2c drivers.  From
  lowest-quality to highest-quality: matched by plausible address only,
  matched by plausible address and poking at the bus to see if the
  device looks reasonable, matched by direct-config “compatible” string,
  matched by direct-config “driver name” string.

— If the “match quality” is merely “plausible address only”, then
  iic_search() will use the probe strategy selected above to see if
  a device responds to that address.
2018-06-07 13:30:49 +00:00
thorpej
f135fe1d80 Back out unintended commits. 2018-06-07 05:56:18 +00:00
thorpej
1adbfe6cdb Adjust come defaults:
- Initial gain -> 16x
- auto_gain -> true
2018-06-07 05:54:23 +00:00
maya
a50c06709e Remove duplicate ; 2018-06-06 01:49:07 +00:00
thorpej
b745c7b03f Update the compat strings to match what Linux uses, per jmcneill@. 2018-05-27 14:03:56 +00:00
thorpej
91d6af5a4b Add a driver for the Taos TSL256x light sensors. 2018-05-27 05:31:20 +00:00
jmcneill
86c215cc57 Add battery voltage, charge current, and discharge current sensors for
AXP803.
2018-05-26 14:39:20 +00:00
thorpej
c98f5f31c8 Fix a problem reported by jmcneill@ where by a system with multuple i2c
busses would end up with "ghost" device instances on the second bus.  This
issue was previously masked on ARM systems by the empty-child-devices
array issue fixed recently (that effectively blocked all indirect config
of i2c busses on those systems).

To fix this problem, we require that indirectly-configured devices have
to fully specify their parent spec and address, e.g.:

foo* at iic0 addr 0x55

NOT

foo* at iic? addr ?

or even:

foo* at iic? addr 0x55

This is needed because of how indirect configuration works... attach
directives in the kernel config file are enumerated, calling the bus's
search routine, which in the case of i2c, enumerates all i2c addresses
and calls the match routine for each address.  Because we can't always
reliably probe for i2c devices, we ended up with erroneous matches.

Direct configuration of i2c is still allowed to use wildcarded parent specs
and locators.
2018-05-15 02:02:18 +00:00
jmcneill
21a656eccc Battery charge state is invalid until we refresh the first time 2018-05-13 22:58:58 +00:00
jmcneill
c60207086a Use IRQs to update status whenever we can. Reduces the amount of work that
needs to be done whenever sysmon_envsys refreshes sensors.
2018-05-13 11:13:02 +00:00
jmcneill
9a41f73f52 Trigger shutdown on POKLIRQ instead of POKSIRQ.
POKSIRQ is triggered if POK remains low for less than IRQLEVEL. This makes
it way too easy to accidentally trigger shutdown. POKLIRQ is triggered if
POK hold time is greater than IRQLEVEL, which is much more reasonable for
this use case.
2018-05-12 01:31:07 +00:00
jmcneill
c917873fbe Fix off by one in axp803 dcdc2/3/4 definitions 2018-05-10 23:57:31 +00:00
thorpej
417749e5df The probe this driver uses is potentially destructive; at the very
least, filter on the I2C address the device is expected at before we
unleash its fury.
2018-05-09 02:46:22 +00:00
jmcneill
76e21d1974 Don't sleep with IPL_VM lock held. 2018-05-07 15:03:19 +00:00
jmcneill
5a236e5088 POKS IRQ register / bit differ between AXP803 and AXP805/806. Handle these
differences.
2018-05-06 14:25:48 +00:00
jmcneill
82e15d7401 No need to read battery capacity warning levels each time the sensor is refreshed 2018-05-05 10:56:40 +00:00
jmcneill
c2f11555e4 Add ACIN and VBUS present sensors 2018-05-05 10:25:59 +00:00
jmcneill
f0ac935e44 axppmic depends on sysmon_envsys 2018-05-05 02:01:34 +00:00
jmcneill
b4d62e188f Add battery sensors. 2018-05-05 00:39:59 +00:00
jmcneill
71a82865f4 Rename axp806pmic to axppmic, and add support for AXP803. 2018-05-04 21:09:55 +00:00
jmcneill
d4efd54a36 Fix pasto 2018-05-04 20:26:50 +00:00
jmcneill
68d92515b3 Add support for poweroff and the power on-off key (POK). 2018-05-03 02:10:17 +00:00
jmcneill
2fea52f446 Use IPL_VM for bus lock so we can do i2c xfers from interrupt context 2018-05-03 02:08:52 +00:00