11 #include <linux/device.h>
12 #include <linux/errno.h>
16 #include <linux/module.h>
18 #include <linux/types.h>
23 #include <asm/uaccess.h>
25 #define stamp(fmt, args...) pr_debug("%s:%i: " fmt "\n", __func__, __LINE__, ## args)
26 #define stampit() stamp("here i am")
27 #define pr_init(fmt, args...) ({ static const __initconst char __fmt[] = fmt; printk(__fmt, ## args); })
29 #define DRIVER_NAME "bfin-otp"
30 #define PFX DRIVER_NAME ": "
47 if (count %
sizeof(
u64))
54 page = *pos / (
sizeof(
u64) * 2);
55 while (bytes_done < count) {
57 stamp(
"processing page %i (0x%x:%s)", page, flags,
59 ret = bfrom_OtpRead(page, flags, &content);
61 stamp(
"error from otp: 0x%x", ret);
65 if (
copy_to_user(buff + bytes_done, &content,
sizeof(content))) {
71 bytes_done +=
sizeof(content);
72 *pos +=
sizeof(content);
80 #ifdef CONFIG_BFIN_OTP_WRITE_ENABLE
81 static bool allow_writes;
88 static u32 bfin_otp_init_timing(
void)
93 tp2 = (2 *
get_sclk() / 10000000) << 8;
95 timing = tp1 | tp2 | tp3;
96 if (bfrom_OtpCommand(
OTP_INIT, timing))
107 static void bfin_otp_deinit_timing(
u32 timing)
111 bfrom_OtpCommand(
OTP_INIT, timing & ~(-1 << 15));
129 if (count %
sizeof(
u64))
137 timing = bfin_otp_init_timing();
146 page = *pos / (
sizeof(
u64) * 2);
147 while (bytes_done < count) {
149 stamp(
"processing page %i (0x%x:%s) from %p", page, flags,
151 if (
copy_from_user(&content, buff + bytes_done,
sizeof(content))) {
155 ret = bfrom_OtpWrite(page, flags, &content);
156 if (ret & OTP_MASTER_ERROR) {
157 stamp(
"error from otp: 0x%x", ret);
163 bytes_done +=
sizeof(content);
164 *pos +=
sizeof(content);
167 bfin_otp_deinit_timing(timing);
189 timing = bfin_otp_init_timing();
192 stamp(
"locking page %lu resulted in 0x%x", arg, otp_result);
193 if (!(otp_result & OTP_MASTER_ERROR))
196 bfin_otp_deinit_timing(timing);
205 allow_writes =
false;
216 # define bfin_otp_write NULL
217 # define bfin_otp_ioctl NULL
223 .read = bfin_otp_read,
228 static struct miscdevice bfin_otp_misc_device = {
231 .fops = &bfin_otp_fops,
240 static int __init bfin_otp_init(
void)
263 static void __exit bfin_otp_exit(
void)