This source file includes following definitions.
- eeprom_93cx6_pulse_high
- eeprom_93cx6_pulse_low
- eeprom_93cx6_startup
- eeprom_93cx6_cleanup
- eeprom_93cx6_write_bits
- eeprom_93cx6_read_bits
- eeprom_93cx6_read
- eeprom_93cx6_multiread
- eeprom_93cx6_readb
- eeprom_93cx6_multireadb
- eeprom_93cx6_wren
- eeprom_93cx6_write
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 #include <linux/kernel.h>
  12 #include <linux/module.h>
  13 #include <linux/delay.h>
  14 #include <linux/eeprom_93cx6.h>
  15 
  16 MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
  17 MODULE_VERSION("1.0");
  18 MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
  19 MODULE_LICENSE("GPL");
  20 
  21 static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
  22 {
  23         eeprom->reg_data_clock = 1;
  24         eeprom->register_write(eeprom);
  25 
  26         
  27 
  28 
  29 
  30 
  31         ndelay(450);
  32 }
  33 
  34 static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
  35 {
  36         eeprom->reg_data_clock = 0;
  37         eeprom->register_write(eeprom);
  38 
  39         
  40 
  41 
  42 
  43 
  44         ndelay(450);
  45 }
  46 
  47 static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
  48 {
  49         
  50 
  51 
  52         eeprom->register_read(eeprom);
  53         eeprom->reg_data_in = 0;
  54         eeprom->reg_data_out = 0;
  55         eeprom->reg_data_clock = 0;
  56         eeprom->reg_chip_select = 1;
  57         eeprom->drive_data = 1;
  58         eeprom->register_write(eeprom);
  59 
  60         
  61 
  62 
  63         eeprom_93cx6_pulse_high(eeprom);
  64         eeprom_93cx6_pulse_low(eeprom);
  65 }
  66 
  67 static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
  68 {
  69         
  70 
  71 
  72         eeprom->register_read(eeprom);
  73         eeprom->reg_data_in = 0;
  74         eeprom->reg_chip_select = 0;
  75         eeprom->register_write(eeprom);
  76 
  77         
  78 
  79 
  80         eeprom_93cx6_pulse_high(eeprom);
  81         eeprom_93cx6_pulse_low(eeprom);
  82 }
  83 
  84 static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
  85         const u16 data, const u16 count)
  86 {
  87         unsigned int i;
  88 
  89         eeprom->register_read(eeprom);
  90 
  91         
  92 
  93 
  94         eeprom->reg_data_in = 0;
  95         eeprom->reg_data_out = 0;
  96         eeprom->drive_data = 1;
  97 
  98         
  99 
 100 
 101         for (i = count; i > 0; i--) {
 102                 
 103 
 104 
 105                 eeprom->reg_data_in = !!(data & (1 << (i - 1)));
 106 
 107                 
 108 
 109 
 110                 eeprom->register_write(eeprom);
 111 
 112                 
 113 
 114 
 115                 eeprom_93cx6_pulse_high(eeprom);
 116                 eeprom_93cx6_pulse_low(eeprom);
 117         }
 118 
 119         eeprom->reg_data_in = 0;
 120         eeprom->register_write(eeprom);
 121 }
 122 
 123 static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
 124         u16 *data, const u16 count)
 125 {
 126         unsigned int i;
 127         u16 buf = 0;
 128 
 129         eeprom->register_read(eeprom);
 130 
 131         
 132 
 133 
 134         eeprom->reg_data_in = 0;
 135         eeprom->reg_data_out = 0;
 136         eeprom->drive_data = 0;
 137 
 138         
 139 
 140 
 141         for (i = count; i > 0; i--) {
 142                 eeprom_93cx6_pulse_high(eeprom);
 143 
 144                 eeprom->register_read(eeprom);
 145 
 146                 
 147 
 148 
 149                 eeprom->reg_data_in = 0;
 150 
 151                 
 152 
 153 
 154                 if (eeprom->reg_data_out)
 155                         buf |= (1 << (i - 1));
 156 
 157                 eeprom_93cx6_pulse_low(eeprom);
 158         }
 159 
 160         *data = buf;
 161 }
 162 
 163 
 164 
 165 
 166 
 167 
 168 
 169 
 170 
 171 
 172 void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
 173         u16 *data)
 174 {
 175         u16 command;
 176 
 177         
 178 
 179 
 180         eeprom_93cx6_startup(eeprom);
 181 
 182         
 183 
 184 
 185         command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
 186         eeprom_93cx6_write_bits(eeprom, command,
 187                 PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
 188 
 189         
 190 
 191 
 192         eeprom_93cx6_read_bits(eeprom, data, 16);
 193 
 194         
 195 
 196 
 197         eeprom_93cx6_cleanup(eeprom);
 198 }
 199 EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
 200 
 201 
 202 
 203 
 204 
 205 
 206 
 207 
 208 
 209 
 210 
 211 
 212 
 213 
 214 void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
 215         __le16 *data, const u16 words)
 216 {
 217         unsigned int i;
 218         u16 tmp;
 219 
 220         for (i = 0; i < words; i++) {
 221                 tmp = 0;
 222                 eeprom_93cx6_read(eeprom, word + i, &tmp);
 223                 data[i] = cpu_to_le16(tmp);
 224         }
 225 }
 226 EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
 227 
 228 
 229 
 230 
 231 
 232 
 233 
 234 
 235 
 236 
 237 void eeprom_93cx6_readb(struct eeprom_93cx6 *eeprom, const u8 byte,
 238         u8 *data)
 239 {
 240         u16 command;
 241         u16 tmp;
 242 
 243         
 244 
 245 
 246         eeprom_93cx6_startup(eeprom);
 247 
 248         
 249 
 250 
 251         command = (PCI_EEPROM_READ_OPCODE << (eeprom->width + 1)) | byte;
 252         eeprom_93cx6_write_bits(eeprom, command,
 253                 PCI_EEPROM_WIDTH_OPCODE + eeprom->width + 1);
 254 
 255         
 256 
 257 
 258         eeprom_93cx6_read_bits(eeprom, &tmp, 8);
 259         *data = tmp & 0xff;
 260 
 261         
 262 
 263 
 264         eeprom_93cx6_cleanup(eeprom);
 265 }
 266 EXPORT_SYMBOL_GPL(eeprom_93cx6_readb);
 267 
 268 
 269 
 270 
 271 
 272 
 273 
 274 
 275 
 276 
 277 
 278 void eeprom_93cx6_multireadb(struct eeprom_93cx6 *eeprom, const u8 byte,
 279         u8 *data, const u16 bytes)
 280 {
 281         unsigned int i;
 282 
 283         for (i = 0; i < bytes; i++)
 284                 eeprom_93cx6_readb(eeprom, byte + i, &data[i]);
 285 }
 286 EXPORT_SYMBOL_GPL(eeprom_93cx6_multireadb);
 287 
 288 
 289 
 290 
 291 
 292 
 293 
 294 
 295 
 296 void eeprom_93cx6_wren(struct eeprom_93cx6 *eeprom, bool enable)
 297 {
 298         u16 command;
 299 
 300         
 301         eeprom_93cx6_startup(eeprom);
 302 
 303         
 304 
 305         command = enable ? PCI_EEPROM_EWEN_OPCODE : PCI_EEPROM_EWDS_OPCODE;
 306         command <<= (eeprom->width - 2);
 307 
 308         eeprom_93cx6_write_bits(eeprom, command,
 309                                 PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
 310 
 311         eeprom_93cx6_cleanup(eeprom);
 312 }
 313 EXPORT_SYMBOL_GPL(eeprom_93cx6_wren);
 314 
 315 
 316 
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 
 325 
 326 
 327 
 328 void eeprom_93cx6_write(struct eeprom_93cx6 *eeprom, u8 addr, u16 data)
 329 {
 330         int timeout = 100;
 331         u16 command;
 332 
 333         
 334         eeprom_93cx6_startup(eeprom);
 335 
 336         command = PCI_EEPROM_WRITE_OPCODE << eeprom->width;
 337         command |= addr;
 338 
 339         
 340         eeprom_93cx6_write_bits(eeprom, command,
 341                                 PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
 342 
 343         
 344         eeprom_93cx6_write_bits(eeprom, data, 16);
 345 
 346         
 347         eeprom->drive_data = 0;
 348         eeprom->reg_chip_select = 1;
 349         eeprom->register_write(eeprom);
 350 
 351         
 352         usleep_range(1000, 2000);
 353 
 354         
 355 
 356         while (true) {
 357                 eeprom->register_read(eeprom);
 358 
 359                 if (eeprom->reg_data_out)
 360                         break;
 361 
 362                 usleep_range(1000, 2000);
 363 
 364                 if (--timeout <= 0) {
 365                         printk(KERN_ERR "%s: timeout\n", __func__);
 366                         break;
 367                 }
 368         }
 369 
 370         eeprom_93cx6_cleanup(eeprom);
 371 }
 372 EXPORT_SYMBOL_GPL(eeprom_93cx6_write);