2 * This software is the confidential and proprietary information
3 * of Samsung Electronics, Inc. ("Confidential Information"). You
4 * shall not disclose such Confidential Information and shall use
5 * it only in accordance with the terms of the license agreement
6 * you entered into with Samsung.
11 * Low-Level Interface Driver
13 * COPYRIGHT(C) Samsung Electronics Co.Ltd. 2009-2010 All Right Reserved.
15 * 2009.02 - First editing by SungHwan.yun <sunghwan.yun@samsung.com> @LDK@
17 * 2009.03 - Currently managed by SungHwan.yun <sunghwan.yun@samsung.com> @LDK@
20 #include <linux/kernel.h>
21 #include <linux/module.h>
24 #if defined(J4FS_USE_XSR)
26 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
27 #include "./Inc/XsrTypes.h"
28 #include "./Inc/STL.h"
30 #include "../../drivers/txsr/Inc/XsrTypes.h"
31 #include "../../drivers/txsr/Inc/STL.h"
34 #elif defined(J4FS_USE_FSR)
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
37 #include "../../tfsr/Inc/FSR.h"
38 #include "../../tfsr/Inc/FSR_STL.h"
40 #include "../fsr/Inc/FSR.h"
41 #include "../fsr/Inc/FSR_STL.h"
44 #elif defined(J4FS_USE_MOVI)
45 /* j4fs device node name */
46 #define J4FS_DEVNAME CONFIG_J4FS_DEVNAME
47 static struct file *j4fs_filp;
53 extern j4fs_device_info device_info;
54 extern unsigned int j4fs_traceMask;
57 * Fills the specified buffer with the number of bytes defined by length from the device's absolute physical address
59 * offset : start physical page number
60 * length : bytes to write
61 * buffer : buffer to write data
63 * The return code should indicate ERROR (1) or OK(0). If the return code indicates ERROR, the dev_ptr->status field should indicate
64 * the return error code.
66 int FlashDevRead(j4fs_device_info *dev_ptr, DWORD offset, DWORD length, BYTE *buffer)
70 int part_id=dev_ptr->device;
78 #if defined(J4FS_USE_XSR)
79 ret = STL_Read(nVol, part_id, offset/512, length/512, buffer);
80 if (ret != STL_SUCCESS) {
81 T(J4FS_TRACE_ALWAYS,("%s %d: Error(offset,length,j4fs_end,nErr)=(0x%x,0x%x,0x%x,0x%x)\n",__FUNCTION__,__LINE__,offset,length,device_info.j4fs_end,ret));
84 #elif defined(J4FS_USE_FSR)
85 ret = FSR_STL_Read(nVol, part_id, offset/512, length/512, buffer, FSR_STL_FLAG_DEFAULT);
86 if (ret != FSR_STL_SUCCESS) {
87 T(J4FS_TRACE_ALWAYS,("%s %d: Error(offset,length,j4fs_end,nErr)=(0x%x,0x%x,0x%x,0x%x)\n",__FUNCTION__,__LINE__,offset,length,device_info.j4fs_end,ret));
90 #elif defined(J4FS_USE_MOVI)
91 if (IS_ERR(j4fs_filp)) {
92 printk("J4FS not available\n");
95 j4fs_filp->f_flags |= O_NONBLOCK;
96 oldfs = get_fs(); set_fs(get_ds());
97 ret = j4fs_filp->f_op->llseek(j4fs_filp, offset, SEEK_SET);
98 ret = j4fs_filp->f_op->read(j4fs_filp, buffer, length, &j4fs_filp->f_pos);
100 j4fs_filp->f_flags &= ~O_NONBLOCK;
102 printk("j4fs_filp->read() failed: %d\n", ret);
113 * This function writes length bytes of data from a specified buffer to the destination address within the device
115 * offset : start physical page number
116 * length : bytes to write
117 * buffer : buffer to write data
119 * The return code should indicate ERROR (1) or OK(0). If the return code indicates ERROR, the dev_ptr->status field should indicate
120 * the return error code.
122 int FlashDevWrite(j4fs_device_info *dev_ptr, DWORD offset, DWORD length, BYTE *buffer)
124 #ifndef J4FS_USE_MOVI
126 int part_id=dev_ptr->device;
134 #if defined(J4FS_USE_XSR)
135 ret = STL_Write(nVol, part_id, offset/512, length/512, buffer);
136 if (ret != STL_SUCCESS) {
137 T(J4FS_TRACE_ALWAYS,("%s %d: Error(offset,length,j4fs_end,nErr)=(0x%x,0x%x,0x%x,0x%x)\n",__FUNCTION__,__LINE__,offset,length,device_info.j4fs_end,ret));
140 #elif defined(J4FS_USE_FSR)
141 ret = FSR_STL_Write(nVol, part_id, offset/512, length/512, buffer, FSR_STL_FLAG_DEFAULT);
142 if (ret != FSR_STL_SUCCESS) {
143 T(J4FS_TRACE_ALWAYS,("%s %d: Error(offset,length,j4fs_end,nErr)=(0x%x,0x%x,0x%x,0x%x)\n",__FUNCTION__,__LINE__,offset,length,device_info.j4fs_end,ret));
146 #elif defined(J4FS_USE_MOVI)
147 if (IS_ERR(j4fs_filp)) {
148 printk("J4FS not available\n");
151 j4fs_filp->f_flags |= O_NONBLOCK;
152 oldfs = get_fs(); set_fs(get_ds());
153 ret = j4fs_filp->f_op->llseek(j4fs_filp, offset, SEEK_SET);
154 ret = j4fs_filp->f_op->write(j4fs_filp, buffer, length, &j4fs_filp->f_pos);
156 j4fs_filp->f_flags &= ~O_NONBLOCK;
158 printk("j4fs_filp->write() failed: %d\n", ret);
169 * In order to reuse the flash media, an erase command must be provided for the FSD. This command erases a single flash erase-block beginning
170 * at the address specified by the aux field in the DEVICE_INFO structure. The blocksize field of the DEVICE_INFO structure is used to force the aux ptr
171 * to a block boundary.
173 * dev_ptr->aux : start block address to be erased
175 int FlashDevErase(j4fs_device_info *dev_ptr)
181 int FlashDevSpecial(j4fs_device_info *dev_ptr, DWORD scmd)
186 // Initialize the internal FSD structures to use a device
206 DWORD media_status_table_size=1; // Media Status Table occupys 1 block
209 j4fs_filp = filp_open(J4FS_DEVNAME, O_RDWR|O_SYNC, 0);
210 if (IS_ERR(j4fs_filp)) {
211 printk("FlashDevMount : filp_open() failed~!: %ld\n", PTR_ERR(j4fs_filp));
214 printk("FlashDevMount : filp_open() OK....!\n");
217 device_info.device=J4FS_PARTITION_ID;
218 device_info.blocksize=PHYSICAL_BLOCK_SIZE;
219 device_info.pagesize=PHYSICAL_PAGE_SIZE;
220 device_info.j4fs_offset=media_status_table_size*device_info.blocksize; // j4fs_offset follows the Media Status Table.
224 int FlashDevUnmount()
227 filp_close(j4fs_filp, NULL);
228 printk("FlashDevUnmount : filp_close() OK....!\n");