Commit Graph

341 Commits

Author SHA1 Message Date
Oleksandr Tymoshenko
e7bf6d7ae9 [twsi] Make extres/clk part conditional based on the EXT_RESOURCES option value
This should fix kernel build for ARMADA38X and possibly some other ARM configs

Approved by:	manu
2018-12-14 21:17:42 +00:00
Emmanuel Vadot
2a3fb901a7 twsi: Clean up marvell part and add support for Marvell 7k/8k
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2018-12-12 22:05:07 +00:00
Emmanuel Vadot
04f9b8a116 Add Silergy SYR827 PMIC driver
SYR827 is a PMIC that can output a voltage from 0.7125V to 1.5V in 12.5mV steps
It's controlled via I2C.

MFC after:	1 month
2018-12-01 20:31:49 +00:00
Ian Lepore
5af4ab6524 Export the eeprom device size via readonly sysctl. Also export the write
page size and address size, although they are likely to be inherently
less-interesting values outside of the driver.
2018-08-13 23:53:11 +00:00
Warner Losh
e4eef18848 Use M. Warner Losh everywhere on my copyrights.
Remove 'All Rights Reserved' where I can.
2018-05-01 16:29:22 +00:00
Oleksandr Tymoshenko
217d17bcd3 Clean up OF_getprop_alloc API
OF_getprop_alloc takes element size argument and returns number of
elements in the property. There are valid use cases for such behavior
but mostly API consumers pass 1 as element size to get string
properties. What API users would expect from OF_getprop_alloc is to be
a combination of malloc + OF_getprop with the same semantic of return
value. This patch modifies API signature to match these expectations.

For the valid use cases with element size != 1 and to reduce
modification scope new OF_getprop_alloc_multi function has been
introduced that behaves the same way OF_getprop_alloc behaved prior to
this patch.

Reviewed by:	ian, manu
Differential Revision:	https://reviews.freebsd.org/D14850
2018-04-08 22:59:34 +00:00
Ian Lepore
b138780b0c Build the ds1672 driver as a module. Add a detach() to unregister the rtc. 2018-03-06 02:30:34 +00:00
Ian Lepore
18029749f4 Fix a paste-o that broke the build. There is no softc pointer here, just
use the dev arg.

Reported by:	Jonathan Looney <jonlooney@gmail.com>
Pointy hat:	ian@
2018-03-06 02:21:41 +00:00
Ian Lepore
6d27b68a1a Switch to the new bcd_clocktime conversion routines, and add calls to the
new clock_dbgprint_xxx() functions.
2018-03-05 00:43:53 +00:00
Ian Lepore
bbff059175 Switch to the new bcd_clocktime conversion routines, and add calls to the
new clock_dbgprint_xxx() functions.
2018-03-05 00:15:56 +00:00
Ian Lepore
29e14eea8c Switch to the new bcd_clocktime conversion routines, and add calls to the
new clock_dbgprint_xxx() functions.
2018-03-04 23:39:40 +00:00
Ian Lepore
89ba361fcc The year is stored in a single byte in sram, in binary format, as a count
of years since the century, so strip the century out when converting to or
from bcd_clocktime format (the conversion routines will infer century by
pivoting on 70).
2018-03-04 21:58:32 +00:00
Ian Lepore
5deff57b6f Convert to the new(ish) bcd_clocktime conversion functions, add calls to
the new debug output functions, and when setting the clock, propagate the
timespec nsecs to the 1/100ths register.
2018-03-04 21:04:30 +00:00
Ian Lepore
02641ce942 Add calls to the new clock_dbgprint_xxx() functions. Also, stop applying
a local .5 second adjustment to the time, since that is now done by the
code in subr_rtc.c.
2018-03-04 19:32:52 +00:00
Ian Lepore
fa9d44f62e Add calls to the new clock_dbgprint_xxx() functions. 2018-03-04 19:26:47 +00:00
Ian Lepore
4fa48f9c58 Oops, fix a paste-o. 2018-03-04 19:25:54 +00:00
Ian Lepore
1844448d8c Add calls to the new clock_dbgprint_xxx() functions. 2018-03-04 19:23:48 +00:00
Ian Lepore
c10acec536 Add calls to the new clock_dbgprint_xxx() functions. 2018-03-04 19:20:11 +00:00
Ian Lepore
683195e410 Fix a paste-o: use the IICBUS version constants, not IICBB bitbang driver's. 2018-03-04 18:58:24 +00:00
Ian Lepore
c5fe9c7b20 Allow i2c hardware drivers to declare their own relationships to ofw_iicbus
rather than relying on a set of canned EARLY_DRIVER_MODULE() statements in
the ofw_iicbus source.  This means hw drivers will no longer be required to
use one of a few predefined driver names.  They will also now be able to
decide themselves if they want to use DRIVER_MODULE or EARLY_DRIVER_MODULE
and to set which pass to attach on for early modules.

Mainly, this adds extern declarations for the driver and devclass variables.
It also renames ofwiicbus_devclass to ofw_iicbus_devclass to be consistant
with the way we use ofw_ prefixes on this stuff.
2018-02-18 19:33:28 +00:00
Ian Lepore
8917c34a82 Follow changes in r328307 by using new IIC_RECURSIVE flag.
The driver now ensures only one thread at a time is running in the API
functions (clock_gettime() and clock_settime()) by specifically requesting
ownership of the i2c bus without using IIC_RECURSIVE, then it does all IO
using IIC_RECURSIVE so that each individual IO operation doesn't try to
re-acquire the bus.

The other IO done by the driver happens at attach or intr_config_hooks time,
when there can't be multiple threads running with the same device instance.
So, the IIC_RECURSIVE flag can be safely ORed into the wait flags for all IO
done by the driver, because it's all either done in a single-threaded
environment, or protected within a block bounded by explict
iicbus_acquire_bus() and iicbus_release_bus() calls.
2018-01-24 03:09:56 +00:00
Ian Lepore
548778ed13 Follow changes in r328307 by using new IIC_RECURSIVE flag.
The driver now ensures only one thread at a time is running in the API
functions (clock_gettime() and clock_settime()) by specifically requesting
ownership of the i2c bus without using IIC_RECURSIVE, then it does all IO
using IIC_RECURSIVE so that each individual IO operation doesn't try to
re-acquire the bus.

The other IO done by the driver happens at attach or intr_config_hooks time,
when there can't be multiple threads running with the same device instance.
So, the IIC_RECURSIVE flag can be safely ORed into the wait flags for all IO
done by the driver, because it's all either done in a single-threaded
environment, or protected within a block bounded by explict
iicbus_acquire_bus() and iicbus_release_bus() calls.
2018-01-24 03:09:41 +00:00
Ian Lepore
ac8f374abf Fix a bug introduced with recursive bus ownership support in r321584.
The recursive ownership support added in r321584 was unconditionally in
effect all the time -- whenever a given i2c slave device instance tried to
lock the i2c bus for exclusive use when it already owned the bus, the call
returned immediately without waiting.  However, many i2c slave drivers use
bus ownership to enforce that only a single thread at a time can be using
the slave device.  The recursive locking changes broke this use case.

Now there is a new flag, IIC_RECURSIVE, which can be mixed in with the
other flags passed to iicbus_acquire_bus() to allow drivers to indicate
when recursive locking is desired.  Using the flag implies that the driver
is managing concurrent access to the device by different threads in some way.

This immediately fixes all existing i2c slave drivers except for the two
i2c RTC drivers which use the recursive locking feature; those will be
fixed in a followup commit.
2018-01-23 23:30:19 +00:00
Ian Lepore
18d61b59bf Switch to using the bcd_clocktime conversion functions that validate the BCD
data without panicking, and have common code for handling AM/PM mode.
2018-01-23 21:36:26 +00:00
Ian Lepore
e324bd4bd6 Switch to using the bcd_clocktime conversion functions that validate the BCD
data without panicking, and have common code for handling AM/PM mode.
2018-01-23 21:31:43 +00:00
Ian Lepore
234add65f7 Switch to using the bcd_clocktime conversion functinos that validate the BCD
data without panicking, and have common code for handling AM/PM mode.
2018-01-23 21:18:15 +00:00
Ian Lepore
a369070143 Convert a collection of unrelated bitwise flags to a collection of boolean
vars in the softc.  It makes the code more compact and readable, and
actually uses less memory too.
2018-01-10 02:57:03 +00:00
Ian Lepore
b33d84e005 Bugfix: don't lose the am/pm mode flag when setting the time. Unlike most
RTC chips that have a control register bit for am/pm mode, the DS13xx series
uses one of the high bits in the hour register.  Thus, when setting the time
in am/pm mode, the am/pm mode flag has to be ORed into the hour.
2018-01-10 02:31:59 +00:00
Ian Lepore
b93c58e168 Bugfix: on RTC chips with a 32-bit binary counter, after reading the time,
return immediately rather than falling through to the logic that reads
BCD-encoded time.
2018-01-10 02:28:10 +00:00
Emmanuel Vadot
b6d40d9394 Change the remaining files using my personnal email address to my freebsd one 2017-12-25 22:09:25 +00:00
Ian Lepore
3102bbe940 Do not give up if writing to the chip's control and status registers fails
during startup.  When a brand new chip leaves the factory, it is in a
special power-saving mode that disables most functions on the chip to
save battery power.  The chip is stuck in this mode until the first write
to the time registers, which automatically clears the special power-saving
mode and starts the oscillator.

Also, the day-of-week register in this chip counts 1-7, not 0-6, so write
the values accordingly.

These changes are based on the patch submitted by Brian Scott, but I
elimated warnings since this condition is expected, and added some comments,
and so in general blame me for any mistakes.

PR:		223642
2017-12-10 18:55:42 +00:00
Pedro F. Giffuni
718cf2ccb9 sys/dev: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-27 14:52:40 +00:00
Justin Hibbits
9a7a0683b1 DS1307: Add the mcp7941x enable bit
Summary:
Existing code recognizes the mcp7941x RTC, but this RTC has an
enable bit at the same location as the "Clock Halt" bit on the ds1307, with an
opposite assertion (set == on, whereas CH set == clock stopped).  Thus the
current code halts the clock, with no way to enable it.

Reviewed By:	ian
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D12961
2017-11-08 01:28:20 +00:00
Michael Zhilin
be04c94e1e [i2c/clock] add support for EPSON RTC-8583
RTC-8583 is time-of-day clock used in some SOHO routers. This clock has
only 2 bits for year values, but thanks to user SRAM it's possible to save
year value and keep it up to date via driver code.

Tested on Planex_MZK-W300NAG (SoC is RT2880)

Submitted by:	Hiroki Mori <yamori83@yahoo.co.jp>
Differential Revision:	https://reviews.freebsd.org/D12833
2017-10-31 12:15:00 +00:00
Ian Lepore
d18915fadb Give icee(4) a detach() method so it can be used as a module. Add a
module makefile for it.
2017-09-17 22:58:13 +00:00
Ian Lepore
813c1b27fe Add a default implementation that returns ENODEV for start, repeat_start,
stop, read, and write methods.  Some controllers don't implement these
individual operations and have only a transfer method.  In that case, we
should return an indication that the device is present but doesn't support
the method, as opposed to the kobj default error ENXIO which makes it
look like the whole device is missing.  Userland tools such as i2c(8) can
use the differing return values to switch between the two different i2c
IO mechanisms.
2017-09-11 23:47:49 +00:00
Ian Lepore
a6e709f29c Add hinted attachment for non-FDT systems. Also, print a message if
setting up the timer fails, because on some types of chips that's the
first attempt to access the device.  If the chip is missing/non-responsive
then you'd get a driver that attached and didn't register the rtc, with
no clue about why.  On other chip types there are inits that come before
timer setup, and they already print messages about errors.
2017-08-14 02:23:10 +00:00
Ian Lepore
098f6cb6e6 Minor fixes and enhancements for the s35390a i2c RTC driver...
- Add FDT probe code.
- Do i2c transfers with exclusive bus ownership.
- Use config_intrhook_oneshot() to defer chip setup because some i2c
  busses can't do transfers without interrupts.
- Add a detach() routine.
- Add to module build.
2017-08-14 00:00:24 +00:00
Ian Lepore
90cff13c3c Remove the old ds1374 driver and use the ds13rtc driver instead. Adjust
several mips config files accordingly.
2017-08-13 22:07:42 +00:00
Ian Lepore
3777ed4378 Change "chiptype" to "compatible". Making the hint name the same as the FDT
property name should make it easier to document the list of names accepted
by both configuration mechanisms.
2017-08-13 21:45:46 +00:00
Ian Lepore
bb2e8108e1 Add a new driver, ds13rtc, that handles all DS13xx series i2c RTC chips.
This driver supports only basic timekeeping functionality.  It completely
replaces the ds133x driver.  It can also replace the ds1374 driver, but that
will take a few other changes in MIPS code and config, and will be committed
separately.  It does NOT replace the existing ds1307 driver, which provides
access to some of the extended features on the 1307 chip, such as controlling
the square wave output signal.  If both ds1307 and ds13rtc drivers are
present, the ds1307 driver will outbid and win control of the device.

This driver can be configured with FDT data, or by using hints on non-FDT
systems.  In addition to the standard hints for i2c devices, it requires
a "chiptype" string of the form "dallas,ds13xx" where 'xx' is the chip id
(i.e., the same format as FDT compat strings).
2017-08-13 21:02:40 +00:00
Ian Lepore
4541b9aab6 Bid for the device with BUS_PROBE_GENERIC, because this is very much a
generic driver with minimal feature support for a large number of chips.
More featureful per-chip drivers might exist (especially out-of-tree) and
those should win the bidding even if they use BUS_PROBE_DEFAULT.
2017-08-12 17:39:32 +00:00
Ian Lepore
94759a2448 Add a driver for the Intersil ISL12xx family of i2c RTC chips.
Supports ISL1209, ISL1218, ISL1219, ISL1220, ISL1221 (just basic RTC
functionality, not all the other fancy stuff the chips can do).
2017-08-01 04:16:52 +00:00
Ian Lepore
012e41a7a8 Bugfixes and enhancements...
Don't enable the oscillator when it is found to be stopped at init time,
just let the first setting of valid time start it.  But still report a dead
battery if it's stopped at init time.

Don't force the chip into 24hr mode, just cope with whatever mode it is
already in.

Schedule the clock_settime() callbacks to align the RTC clock to top of
second when setting it.
2017-07-31 22:00:00 +00:00
Ian Lepore
13fd9ff767 No need to call getnanotime() now that the waiting is done by the central
subr_rtc code, switch from CLOCKF_SETTIME_NO_TS to CLOCKF_SETTIME_NO_ADJ
so that we get fed a timestamp, but it's not adjusted to compensate for
inaccuracy in setting time.
2017-07-31 21:53:00 +00:00
Ian Lepore
def6c0c3ee Restore a few rather important lines of code that got fumbled in r321746. 2017-07-31 16:46:16 +00:00
Ian Lepore
bf9c1267f3 Check the clock-halted flag every time the clock is read, not just once
at startup.  The flag stays set until the clock is loaded with good time,
so we need to keep saying the time is invalid until that happens.
2017-07-31 15:24:40 +00:00
Ian Lepore
ccf32b9887 Add a detach() method. 2017-07-31 14:58:01 +00:00
Ian Lepore
cf24e991a6 Switch from using iic_transfer() to iicdev_readfrom/writeto(), mostly so
that transfers will be done with proper ownership of the bus. No
behavioral changes.  Also add a detach() method.
2017-07-31 14:57:02 +00:00
Ian Lepore
4c0c8a36da Remove now-unused variable. 2017-07-31 03:19:16 +00:00
Ian Lepore
02d094ff04 Use the new clock_schedule() to arrange for clock_settime() to be called
at the right time to keep the RTC hardware time in sync, instead of using
pause_sbt() to sleep until the right time.
2017-07-31 01:36:51 +00:00
Ian Lepore
2e639013ed Fix AM/PM mode handling. The bits to mask off in the hours register changes
between 12/24 hour mode.  Also fix conversion between 12 and 24 hour mode.
It's not as easy as adding/subtracting 12, because the clock doesn't roll
over 11->0, it rolls over 12->1; 0 isn't a valid hour in AM/PM mode.
2017-07-30 19:58:31 +00:00
Ian Lepore
d0462804d4 Bugfixes and enhancements...
Don't enable the oscillator when it is found to be stopped at init time,
just let the first setting of valid time start it.  But still report a dead
battery if it's stopped at init time.

Don't force the chip into 24hr mode, just cope with whatever mode it is
already in.

Align the RTC clock to top of second when setting it.
2017-07-30 18:46:38 +00:00
Ian Lepore
723a81dec6 Switch from using iic_transfer() to iicdev_readfrom/writeto(), mostly so
that transfers will be done with proper ownership of the bus. No
behavioral changes.
2017-07-30 16:17:06 +00:00
Ian Lepore
e25f1cf5be Fix building this driver on non-FDT platforms. 2017-07-30 00:00:30 +00:00
Ian Lepore
207fe81ea8 Replace the pcf8563 i2c RTC driver with a new nxprtc driver which handles
all the chips in the NXP PCA212x and PCA/PCF85xx series.  In addition to
supporting more chips, this driver uses the countdown timer on the chips as
a fractional seconds counter, giving it a resolution of about 15 milliseconds.
2017-07-29 23:45:57 +00:00
Ian Lepore
34199ee049 Add support for tracking nested calls to iicbus_request/release_bus().
Usually it is sufficient to use iicbus_transfer_excl(), or one of the
higher-level convenience functions that use it, to reserve the bus for the
duration of each register access.  Occasionally it is important that a
series of accesses or read-modify-write operations must be done without any
other intervening access to the device, to prevent corrupting state.

Without support for nested request/release, slave device drivers would have
to stop using high-level convenience functions and resort to working with
arrays of iic_msg structs just for a few operations (often involving
one-time device setup or infrequent configuration changes).

The changes here appear large from a glance at the diff, but in fact they're
nearly trivial, and the large diff is because of changes in indentation and
the re-wrapping of comments caused by that.  One notable change is that
iicbus_release_bus() now ignores the IICBUS_CALLBACK(IIC_RELEASE_BUS) return
value.  The old error handling left the bus in a kind of limbo state where
it was still owned at the iicbus layer, but drivers rarely check the return
of the release call, and it's unclear what they would do to recover from an
error return anyway.  No existing low-level drivers return any kind of error
from IIC_RELEASE_BUS except one EINVAL for "you don't own the bus", to which
the right response is probably to carry on with the process of releasing the
reference to the bus anyway.
2017-07-26 21:06:26 +00:00
Ian Lepore
7ec74c580d Add a pair of convenience routines for doing simple "register" read/writes
on i2c devices, where the "register" can be any length.

Many (perhaps most) common i2c devices are organized as a collection of
(usually 1-byte-wide) registers, and are accessed by first writing a 1-byte
register index/offset number, then by reading or writing the data.
Generally there is an auto-increment feature so the when multiple bytes
are read or written, multiple contiguous registers are accessed.

Most existing slave device drivers allocate an array of iic_msg structures,
fill in all the transfer info, and invoke iicbus_transfer().  These new
functions commonize all that and reduce register access to a simple call
with a few arguments.
2017-07-26 20:40:24 +00:00
Ian Lepore
a14af83085 Fix drivers that assume ticks starts at zero. These drivers all have logic
similar to "if (ticks > localvar+interval) {localvar=ticks; ...}" where
localvar is initialized to zero.  Ticks is initialized to a negative value
since r278230, and that leads to these if statements never being true.
2017-07-06 17:03:22 +00:00
Ian Lepore
930b312319 Add iic_recover_bus(), a helper function that can be used by any i2c driver
which is able to manipulate the clock and data lines directly.

When an i2c bus is hung by a slave device stuck in the middle of a
transaction that didn't complete properly, this function manipulates the
clock and data lines in a sequence known to reliably reset slave devices.
The most common cause of a hung i2c bus is a system reboot in the middle of
an i2c transfer (so it doesnt' happen often, but now there is a way other
than power cycling to recover from it).
2017-06-29 01:50:58 +00:00
Ian Lepore
f03b277259 If an i2c transfer ends due to error, issue a stop on the bus even if the
nostop option is set, if a start was issued.

The nostop option doesn't mean "never issue a stop" it means "only issue
a stop after the last in a series of transfers".  If the transfer ends
due to error, then that was the last transfer in the series, and a stop
is required.

Before this change, any error during a transfer when nostop is set would
effectively hang the bus, because sc->started would never get cleared,
and that caused all future calls to iicbus_start() to return an error
because it looked like the bus was already active.  (Unrelated errors in
handling the nostop option, to be addressed separately, could lead to
this bus hang condition even on busses that don't set the nostop option.)
2017-06-29 00:29:15 +00:00
Luiz Otavio O Souza
aee2c3a86a Always ignore the START and STOP bits whenever the control register is
being overwritten, they are set only bits (cleared by hardware).

Disable the Acknowledge of the controller slave address.  The slave mode is
not supported.

Make sure the interrupt flag bit is being cleared as recommended, add a
delay() _after_ clear the interrupt bit.

Sponsored by:	Rubicon Communications, LLC (Netgate)
2017-06-20 18:38:51 +00:00
Luiz Otavio O Souza
872625501b Make ofw_iicbus attach to twsi I2C controllers.
Add the ofw_bus_get_node() callback in mv_twsi, it is mandatory for the
ofw_iicbus usage.

Sponsored by:	Rubicon Communications, LLC (Netgate)
2017-06-20 18:25:27 +00:00
Pedro F. Giffuni
4d24901ac9 sys/dev: Replace zero with NULL for pointers.
Makes things easier to read, plus architectures may set NULL to something
different than zero.

Found with:	devel/coccinelle
MFC after:	3 weeks
2017-02-20 03:43:12 +00:00
Andriy Gapon
88cc0bb940 iicsmb: SMB_MAXBLOCKSIZE can be used again
The constant was set to the correct value in r308242.
While there, fix iicsmb_bread() to not use a value of an out parameter
'count'.

MFC after:	3 weeks
X-MFC after:	r308242
2016-11-11 15:11:54 +00:00
Andriy Gapon
448897d366 add iic interface to ig4 driver, move isl and cyapa to iicbus
Summary:
The hardware does not expose a classic SMBus interface.
Instead it has a lower level interface that can express a far richer
I2C protocol than what smbus offers.  However, the interface does not
provide a way to explicitly generate the I2C stop and start conditions.
It's only possible to request that the stop condition is generated
after transferring the next byte in either direction.  So, at least
one data byte must always be transferred.
Thus, some I2C sequences are impossible to generate, e.g., an equivalent
of smbus quick command (<start>-<slave addr>-<r/w bit>-<stop>).

At the same time isl(4) and cyapa(4) are moved to iicbus and now they use
iicbus_transfer for communication.  Previously they used smbus_trans()
interface that is not defined by the SMBus protocol and was implemented
only by ig4(4).  In fact, that interface was impossible to implement
for the typical SMBus controllers like intpm(4) or ichsmb(4) where
a type of the SMBus command must be programmed.

The plan is to remove smbus_trans() and all its uses.
As an aside, the smbus_trans() method deviates from the standard,
but perhaps backwards, FreeBSD convention of using 8-bit slave
addresses (shifted by 1 bit to the left).  The method expects
7-bit addresses.

There is a user facing consequence of this change.
A user must now provide device hints for isl and cyapa that specify an iicbus to use
and a slave address on it.
On Chromebook hardware where isl and cyapa devices are commonly found
it is also possible to use a new chromebook_platform(4) driver that
automatically configures isl and cyapa devices.  There is no need to
provide the device hints in that case,

Right now smbus(4) driver tries to discover all slaves on the bus.
That is very dangerous.  Fortunately, the probing code uses smbus_trans()
to do its job, so it is really enabled for ig4 only.
The plan is to remove that auto-probing code and smbus_trans().

Tested by:	grembo, Matthias Apitz <guru@unixarea.de> (w/o
		chromebook_platform)
Discussed with:	grembo, imp
Reviewed by:	wblock (docs)
MFC after:	1 month
Relnotes:	yes
Differential Revision: https://reviews.freebsd.org/D8172
2016-10-30 12:15:33 +00:00
Andriy Gapon
f1519c0157 convert iicsmb to use iicbus_transfer for all operations
Previously the driver used more low level operations like iicbus_start
and iicbus_write.  The problem is that those operations are not
implemented by iicbus(4) and the calls were effectively routed to
a driver to which the bus is attached.
But not all of the controllers implement such low level operations
while all of the drivers are expected to have iicbus_transfer.

While there fix incorrect implementation of iicsmb_bwrite and iicsmb_bread.
The former should send a byte count before the actual bytes, while the
latter should first receive the byte count and then receive the bytes.

I have tested only these commands:
- quick (r/w)
- send byte
- receive byte
- read byte
- write byte

MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D8170
2016-10-13 07:25:18 +00:00
Warner Losh
604d83bdce Implement iicbus_write_ivar and impelemnt the NOSTOP ivar in both read
and write.
2016-10-02 17:36:55 +00:00
Justin Hibbits
4332304f56 Fix ds1307 probing
'compat' can never be NULL, because the compatible check loop ends when
compat->ocd_str is NULL.  This causes ds1307 to attach to any unclaimed i2c
device.
2016-09-24 05:27:12 +00:00
Jared McNeill
8dd48c60a0 Add driver for Silergy Corp. SY8106A buck regulator. 2016-09-05 13:39:54 +00:00
Michal Meloun
895c8b1c39 INTRNG: Rework handling with resources. Partially revert r301453.
- Read interrupt properties at bus enumeration time and store
   it into global mapping table.
 - At bus_activate_resource() time, given mapping entry is resolved and
   connected to real interrupt source. A copy of mapping entry is attached
   to given resource.
 - At bus_setup_intr() time, mapping entry stored in resource is used
   for delivery of requested interrupt configuration.
 - For MSI/MSIX interrupts, mapping entry is created within
   pci_alloc_msi()/pci_alloc_msix() call.
 - For legacy PCI interrupts, mapping entry must be created within
   pcib_route_interrupt() by pcib driver itself.

Reviewed by: nwhitehorn, andrew
Differential Revision: https://reviews.freebsd.org/D7493
2016-08-19 10:52:39 +00:00
Michal Meloun
dac935533b EXTRES: Add OF node as argument to all <foo>_get_by_ofw_<bar>() functions.
In some cases, the driver must handle given properties located in
specific OF subnode. Instead of creating duplicate set of function, add
'node' as argument to existing functions, defaulting it to device OF node.

MFC after: 3 weeks
2016-07-10 18:28:15 +00:00
Svatopluk Kraus
ad5244ece1 INTRNG - change the way how an interrupt mapping data are provided
to the framework in OFW (FDT) case.

This is a follow-up to r301451.

Differential Revision:	https://reviews.freebsd.org/D6634
2016-06-05 16:20:12 +00:00
Emmanuel Vadot
30068a1de9 Add support for interrupts, sensors and GPIO for AXP209 PMIC.
Pressing the PEK (power enable key) will shutdown the board.
Some events are reported to devd via system "PMU" and subsystem
"Battery", "AC" and "USB" such as connected/disconnected.
Some sensors values (power source voltage/current) are reported via
sysctl (dev.axp209_pmu.X.)
It also expose a gpioc node usable in kernel and userland. Only 3 of
the 4 GPIO are exposed (The GPIO3 is different and mostly unused on
boards). Most popular boards uses GPIO1 as a sense pin for OTG power.
Add a dtsi file that adds gpio-controller capability to the device as
upstream doesn't defined it and include it in our custom DTS.

Reviewed by:	jmcneill
Approved by:	cognet (mentor)
Differential Revision:	https://reviews.freebsd.org/D6135
2016-05-26 21:09:07 +00:00
Luiz Otavio O Souza
8ba8cb912b Move the OFW iicbus code to dev/iicbus to stop polluting dev/ofw with
unrelated code.

Discussed with:		nwhitehorn (a long time ago)
2016-05-24 01:33:49 +00:00
Luiz Otavio O Souza
9d6672e13b Fix the deciKelvin to Celsius conversion in kernel.
After r285994, sysctl(8) was fixed to use 273.15 instead of 273.20 as 0C
reference and as result, the temperature read in sysctl(8) now exibits a
+0.1C difference.

This commit fix the kernel references to match the reference value used in
sysctl(8) after r285994.

Sponsored by:	Rubicon Communications (Netgate)
2016-05-22 13:58:32 +00:00
Luiz Otavio O Souza
ad802dc4e3 Remove a couple of extra blank lines. 2016-05-22 04:09:05 +00:00
Jason A. Harmening
523a6367e4 iic_rdwr_data->nmsgs is uint32_t, so limit the allowable number of messages to prevent memory exhaustion and short allocations on 32-bit systems. Since iicrdwr is intended to be a workalike of a Linux i2c-dev call, use the same limit of 42 that Linux uses.
Also check the return value of copyin(9) to prevent unnecessary allocation in the failure case.

Submitted by:	ngie
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D5155
2016-05-20 03:03:04 +00:00
Oleksandr Tymoshenko
0cc376c134 Use OF_prop_free instead of direct call to free(9)
Reviewed by:	jhibbits
2016-05-14 20:06:38 +00:00
Jared McNeill
c9aad79aa9 Add allwinner,sun8i-a83t-i2c to the list of compatible devices. 2016-05-14 18:02:47 +00:00
Pedro F. Giffuni
453130d9bf sys/dev: minor spelling fixes.
Most affect comments, very few have user-visible effects.
2016-05-03 03:41:25 +00:00
Jared McNeill
6a05f063ed Convert Allwinner port to extres clk/hwreset/regulator APIs.
Reviewed by:		andrew, gonzo, Emmanuel Vadot <manu@bidouilliste.com>
Approved by:		gonzo (mentor)
Differential Revision:	https://reviews.freebsd.org/D5752
2016-04-06 23:11:03 +00:00
Justin Hibbits
cc8a3448d9 Add support for the Microchip mcp7941x.
This is compatible with the ds1307, but comparing the mcp7941x datasheet vs the
ds1307 code, appears there is one bit placement difference, so that is now
accounted for.

Relnotes:	yes
2016-04-05 03:27:33 +00:00
Justin Hibbits
f8fd3fb518 Fix the resource_list_print_type() calls to use uintmax_t.
Missed a bunch from r297000.
2016-03-22 22:25:08 +00:00
Justin Hibbits
c47476d7e6 Migrate many bus_alloc_resource() calls to bus_alloc_resource_anywhere().
Most calls to bus_alloc_resource() use "anywhere" as the range, with a given
count.  Migrate these to use the new bus_alloc_resource_anywhere() API.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D5370
2016-02-27 03:38:01 +00:00
Andrew Turner
461a7671c7 Add the start of support for the Allwinner A31 clocks. It only adds
support for the i2c, mmc, and gmac clocks. Further clocks can be added as
needed.

Submitted by:	Emmanuel Vadot <manu@bidouilliste.com>
Reviewed by:	jmcneill
Differential Revision:	https://reviews.freebsd.org/D5339
2016-02-26 13:53:09 +00:00
Andrew Turner
740be1dc58 Fix the spelling of OF_getencprop. It will fix the data correctly for the
endian of the CPU so there is no need to call fdt32_to_cpu.

Sponsored by:	ABT Systems Ltd
2016-02-15 17:14:10 +00:00
Andrew Turner
5f250b53e8 Add support for the Allwinner i2c device. This is similar to the existing
Marvell twsi part, however uses different register locations, as such split
the existing driver into Marvell and Allwinner attachments.

While here clean a few style issues.

Submitted by:	Emmanuel Vadot <manu@bidouilliste.com>
Differential Revision:	https://reviews.freebsd.org/D4846
2016-02-15 15:11:26 +00:00
Andrew Turner
632381ed9d Move the twsi driver source to be under iicbus. It is in a separate
directory as it is expected multiple attachments will be added for the SoC
families that use this hardware.

Sponsored by:	ABT Systems Ltd
2016-02-14 23:51:13 +00:00
Enji Cooper
d52f763c21 Use the correct type for i when iterating over buf to avoid unlikely
negative array indexing in iicrdwr(..)

Differential Revision: https://reviews.freebsd.org/D5132
Obtained from: HardenedBSD
PR: 206754
Reported by: CTurt <cturt@hardenedbsd.org>
Submitted by: Madhi Moktari <mokhi64@gmail.com>
Sponsored by: EMC / Isilon Storage Division
2016-01-30 18:33:23 +00:00
Ian Lepore
b180eb215d Add FDT compatibility to the icee driver.
The FDT bindings for eeprom parts don't include any metadata about the
device other than the part name encoded in the compatible property.
Instead, a driver is required to have a compiled-in table of information
about the various parts (page size, device capacity, addressing scheme).  So
much for FDT being an abstract description of hardware characteristics, huh?

In addition to the FDT-specific changes, this also switches to using the
newer iicbus_transfer_excl() mechanism which holds bus ownership for the
duration of the transfer.  Previously this code held the bus across all
the transfers needed to complete the user's IO request, which could be
up to 128KB of data which might occupy the bus for 10-20 seconds.  Now the
bus will be released and re-aquired between every page-sized (8-256 byte)
transfer, making this driver a much nicer citizen on the i2c bus.

The hint-based configuration mechanism is still in place for non-FDT systems.

Michal Meloun contributed some of the code for these changes.
2015-10-22 01:04:31 +00:00
Ian Lepore
4c1e5d32b2 Add iicbus_transfer_excl(), a helper routine to do an i2c bus transaction
while holding exclusive ownership of the bus.  This is the routine most
slave drivers should use unless they have a need to acquire and hold the
bus across a series of related operations that involves multiple transfers.
2015-10-22 00:54:59 +00:00
Jean-Sébastien Pédron
238b89fcad iicbus: Use device_delete_children() instead of explicit child removal
If the bus is detached and deleted by a call to device_delete_child() or
device_delete_children() on a device higher in the tree, I²C children
were already detached and deleted. So the device_t pointer stored in sc
points to freed memory: we must not try to delete it again.

By using device_delete_children(), we let subr_bus.c figure out if there
are children to take care of.

While here, make sure iicbus_detach() and iicoc_detach() call
device_delete_children() too, to be safe.

Reviewed by:	jhb, imp
Approved by:	jhb, imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D3926
2015-10-20 19:52:59 +00:00
Jean-Sébastien Pédron
b90d6d94c1 iicbus: Remove trailing whitespaces
MFC after:	1 week
2015-10-20 19:47:08 +00:00
Ian Lepore
73440c336d Replace a local sx lock that allowed only one client at a time to access
an eeprom device with iicbus_request/release_bus(), which achieves the
same effect and also keeps other i2c slave drivers from clashing on the bus.
2015-10-10 19:51:00 +00:00
Ian Lepore
b16c6d237b Translate iic hardware layer status values to errno return values. 2015-10-10 02:29:02 +00:00
Ian Lepore
d0b70953fb Add a short name, IIC_INTRWAIT, for the common case (IIC_INTR | IIC_WAIT). 2015-10-10 02:06:07 +00:00
Ian Lepore
4006520bea Fix more cases of iicbus-layer functions that must return IIC_Exxxx values. 2015-10-10 00:12:03 +00:00
Ian Lepore
48e5b4261a Return only IIC_Exxxx status values from iicbus-layer functions. Most of
these functions are thin wrappers around calling the hardware-layer driver,
but some of them do sanity checks and return an error.  Since the hardware
layer can only return IIC_Exxxxx status values, the iicbus helper functions
must also adhere to that, so that drivers at higher layers can assume that
any non-zero status value is an IIC_Exxxx value that provides details about
what happened at the hardware layer (sometimes those details are important
for certain slave drivers).
2015-10-09 23:58:19 +00:00
Ian Lepore
df38292a85 Add iic2errno(), a helper function to translate IIC_Exxxxx status values to
errno values that are at least vaguely equivelent.  Also add a new status
value, IIC_ERESOURCE, to indicate a failure to acquire memory or other
required resources to complete a transaction.

The IIC_Exxxxxx values are supposed to communicate low-level details of the
i2c transaction status between the lowest-layer hardware driver and
higher-layer bus protocol and device drivers for slave devices on the bus.
Most of those slave drivers just return all status values from the lower
layers directly to their callers, resulting in crazy error reporting from a
user's point of view (things like timeouts being reported as "no such
process").  Now there's a helper function to make it easier to start
cleaning up all those drivers.
2015-10-09 23:20:08 +00:00