Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: add snvs srtc support #1700

Merged
merged 1 commit into from
Jul 19, 2017
Merged

drivers: add snvs srtc support #1700

merged 1 commit into from
Jul 19, 2017

Conversation

MrVan
Copy link
Contributor

@MrVan MrVan commented Jul 18, 2017

Introduce i.MX SNVS SRTC support. The SRTC works with 32.768KHz.
The SRTC is in SNVS_LP domain. The SNVS_LP is a data storage
subsystem with enhanced security capabilities. Its purpose is to store
and protect system data, regardless of the main system power state.
SNVS_LP is in the always-powered-up domain, which is a separate power
domain with its own power supply. When the chip power supply domain
loses power, SNVS_LP continues to operate normally.

Since OP-TEE does not care about calendar time, there is no need
to update calendar time, we only need to read the counter and
get out the time.

The plat_prng_add_jitter_entropy is reused from tee_time_arm_cntpct.c.

This driver works on i.MX7D-SDB with CFG_IMX_SNVS=y and CFG_SECURE_TIME_SOURCE_REE=n and invoke "snvs_srtc_enable(true)" in plat_cpu_reset_late. In linux side, needs to first disable SNVS SRTC in dts.
There are two issues #1352 #1673 discussing SRTC support. Currently, the snvs srtc only support rtc counter reading and no set time. Moving SRTC to OP-TEE will break the linux to use SRTC, so needs to add SIP/OEM to support Linux driver could set some SNVS SRTC register to trigger alarm and wakeup system.

Signed-off-by: Peng Fan [email protected]

* When cpu/bus runs at low freq, we may never get same value
* during two consecutive read, so only compare the second value.
*/
} while ((val1 >> CNT_TO_SECS_SHIFT) != (val2 >> CNT_TO_SECS_SHIFT));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we read it twice and compare the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the value is in two registers, first read low, then read high, low may overflow. The two reads is to keep high consistent and handle low register overflow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see.

REGISTER_TIME_SOURCE(snvs_srtc_time_source)

/* Needs to be invoked before service_init */
int snvs_srtc_enable(bool enable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type should be TEE_Result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in V2.

}
}
if (bytes) {
FMSG("%s: 0x%02X\n", __func__,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n isn't needed
To avoid the suspicious cast you could replace the X", with " PRIX16

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in V2.

}
if (bytes) {
FMSG("%s: 0x%02X\n", __func__,
(int)acc & ((1 << (bytes * 8)) - 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the BIT32() macro instead of 1 << whatever, perhaps GENMASK_32() is an even better choice here.
Using signed types and bit operations is balancing on the border of undefined behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in V2. This piece code is reused from arm cnt part.

* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IMX_SNVS_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use __DRIVERS_IMX_SNVS_H as guard instead.


#include <types_ext.h>

int snvs_srtc_enable(bool enable);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this function as snvs_srtc_enable(false) seems a bit confusing.
I'd prefer snvc_srtc_enable(void) and snvc_srtc_dissable(void).

It it's to be only one function, perhaps snvc_srtc_init(bool enable) or snvc_srtc_set_status(bool enable)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when SRTC starts, it seems disabling it is not a good idea. I'll refine this part to make it only have enabling function.

@MrVan
Copy link
Contributor Author

MrVan commented Jul 18, 2017

@jenswi-linaro Review updated.

}
if (bytes) {
FMSG("%s: 0x%02" PRIX16, __func__,
(int)acc & GENMASK_32(bytes * 8, 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop the unneeded cast (int) also

@MrVan
Copy link
Contributor Author

MrVan commented Jul 18, 2017

Updated with int removed.

@jenswi-linaro
Copy link
Contributor

Reviewed-by: Jens Wiklander <[email protected]>

Introduce i.MX SNVS SRTC support. The SRTC works with 32.768KHz.
The SRTC is in SNVS_LP domain. The SNVS_LP is a data storage
subsystem with enhanced security capabilities. Its purpose is to store
and protect system data, regardless of the main system power state.
SNVS_LP is in the always-powered-up domain, which is a separate power
domain with its own power supply. When the chip power supply domain
loses power, SNVS_LP continues to operate normally.

Since OP-TEE does not care about calendar time, there is no need
to update calendar time, we only need to read the counter and
get out the time.

The plat_prng_add_jitter_entropy is reused from tee_time_arm_cntpct.c.

Signed-off-by: Peng Fan <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
@MrVan
Copy link
Contributor Author

MrVan commented Jul 19, 2017

tags applied.

@jforissier jforissier merged commit c6ac89b into OP-TEE:master Jul 19, 2017
@MrVan MrVan deleted the snvs-rtc branch September 29, 2017 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants