Lines Matching +full:eeprom +full:- +full:data
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
7 * Abstract: EEPROM reader routines for 93cx6 chipsets.
18 MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
21 static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom) in eeprom_93cx6_pulse_high() argument
23 eeprom->reg_data_clock = 1; in eeprom_93cx6_pulse_high()
24 eeprom->register_write(eeprom); in eeprom_93cx6_pulse_high()
34 static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom) in eeprom_93cx6_pulse_low() argument
36 eeprom->reg_data_clock = 0; in eeprom_93cx6_pulse_low()
37 eeprom->register_write(eeprom); in eeprom_93cx6_pulse_low()
47 static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom) in eeprom_93cx6_startup() argument
52 eeprom->register_read(eeprom); in eeprom_93cx6_startup()
53 eeprom->reg_data_in = 0; in eeprom_93cx6_startup()
54 eeprom->reg_data_out = 0; in eeprom_93cx6_startup()
55 eeprom->reg_data_clock = 0; in eeprom_93cx6_startup()
56 eeprom->reg_chip_select = 1; in eeprom_93cx6_startup()
57 eeprom->drive_data = 1; in eeprom_93cx6_startup()
58 eeprom->register_write(eeprom); in eeprom_93cx6_startup()
63 eeprom_93cx6_pulse_high(eeprom); in eeprom_93cx6_startup()
64 eeprom_93cx6_pulse_low(eeprom); in eeprom_93cx6_startup()
67 static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom) in eeprom_93cx6_cleanup() argument
72 eeprom->register_read(eeprom); in eeprom_93cx6_cleanup()
73 eeprom->reg_data_in = 0; in eeprom_93cx6_cleanup()
74 eeprom->reg_chip_select = 0; in eeprom_93cx6_cleanup()
75 eeprom->register_write(eeprom); in eeprom_93cx6_cleanup()
80 eeprom_93cx6_pulse_high(eeprom); in eeprom_93cx6_cleanup()
81 eeprom_93cx6_pulse_low(eeprom); in eeprom_93cx6_cleanup()
84 static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom, in eeprom_93cx6_write_bits() argument
85 const u16 data, const u16 count) in eeprom_93cx6_write_bits() argument
89 eeprom->register_read(eeprom); in eeprom_93cx6_write_bits()
92 * Clear data flags. in eeprom_93cx6_write_bits()
94 eeprom->reg_data_in = 0; in eeprom_93cx6_write_bits()
95 eeprom->reg_data_out = 0; in eeprom_93cx6_write_bits()
96 eeprom->drive_data = 1; in eeprom_93cx6_write_bits()
101 for (i = count; i > 0; i--) { in eeprom_93cx6_write_bits()
105 eeprom->reg_data_in = !!(data & (1 << (i - 1))); in eeprom_93cx6_write_bits()
108 * Write the bit to the eeprom register. in eeprom_93cx6_write_bits()
110 eeprom->register_write(eeprom); in eeprom_93cx6_write_bits()
115 eeprom_93cx6_pulse_high(eeprom); in eeprom_93cx6_write_bits()
116 eeprom_93cx6_pulse_low(eeprom); in eeprom_93cx6_write_bits()
119 eeprom->reg_data_in = 0; in eeprom_93cx6_write_bits()
120 eeprom->register_write(eeprom); in eeprom_93cx6_write_bits()
123 static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom, in eeprom_93cx6_read_bits() argument
124 u16 *data, const u16 count) in eeprom_93cx6_read_bits() argument
129 eeprom->register_read(eeprom); in eeprom_93cx6_read_bits()
132 * Clear data flags. in eeprom_93cx6_read_bits()
134 eeprom->reg_data_in = 0; in eeprom_93cx6_read_bits()
135 eeprom->reg_data_out = 0; in eeprom_93cx6_read_bits()
136 eeprom->drive_data = 0; in eeprom_93cx6_read_bits()
141 for (i = count; i > 0; i--) { in eeprom_93cx6_read_bits()
142 eeprom_93cx6_pulse_high(eeprom); in eeprom_93cx6_read_bits()
144 eeprom->register_read(eeprom); in eeprom_93cx6_read_bits()
149 eeprom->reg_data_in = 0; in eeprom_93cx6_read_bits()
154 if (eeprom->reg_data_out) in eeprom_93cx6_read_bits()
155 buf |= (1 << (i - 1)); in eeprom_93cx6_read_bits()
157 eeprom_93cx6_pulse_low(eeprom); in eeprom_93cx6_read_bits()
160 *data = buf; in eeprom_93cx6_read_bits()
164 * eeprom_93cx6_read - Read a word from eeprom
165 * @eeprom: Pointer to eeprom structure
167 * @data: target pointer where the information will have to be stored
169 * This function will read the eeprom data as host-endian word
170 * into the given data pointer.
172 void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word, in eeprom_93cx6_read() argument
173 u16 *data) in eeprom_93cx6_read() argument
178 * Initialize the eeprom register in eeprom_93cx6_read()
180 eeprom_93cx6_startup(eeprom); in eeprom_93cx6_read()
185 command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word; in eeprom_93cx6_read()
186 eeprom_93cx6_write_bits(eeprom, command, in eeprom_93cx6_read()
187 PCI_EEPROM_WIDTH_OPCODE + eeprom->width); in eeprom_93cx6_read()
189 if (has_quirk_extra_read_cycle(eeprom)) { in eeprom_93cx6_read()
190 eeprom_93cx6_pulse_high(eeprom); in eeprom_93cx6_read()
191 eeprom_93cx6_pulse_low(eeprom); in eeprom_93cx6_read()
197 eeprom_93cx6_read_bits(eeprom, data, 16); in eeprom_93cx6_read()
200 * Cleanup eeprom register. in eeprom_93cx6_read()
202 eeprom_93cx6_cleanup(eeprom); in eeprom_93cx6_read()
207 * eeprom_93cx6_multiread - Read multiple words from eeprom
208 * @eeprom: Pointer to eeprom structure
210 * @data: target pointer where the information will have to be stored
213 * This function will read all requested words from the eeprom,
219 void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word, in eeprom_93cx6_multiread() argument
220 __le16 *data, const u16 words) in eeprom_93cx6_multiread() argument
227 eeprom_93cx6_read(eeprom, word + i, &tmp); in eeprom_93cx6_multiread()
228 data[i] = cpu_to_le16(tmp); in eeprom_93cx6_multiread()
234 * eeprom_93cx6_readb - Read a byte from eeprom
235 * @eeprom: Pointer to eeprom structure
237 * @data: target pointer where the information will have to be stored
239 * This function will read a byte of the eeprom data
240 * into the given data pointer.
242 void eeprom_93cx6_readb(struct eeprom_93cx6 *eeprom, const u8 byte, in eeprom_93cx6_readb() argument
243 u8 *data) in eeprom_93cx6_readb() argument
249 * Initialize the eeprom register in eeprom_93cx6_readb()
251 eeprom_93cx6_startup(eeprom); in eeprom_93cx6_readb()
256 command = (PCI_EEPROM_READ_OPCODE << (eeprom->width + 1)) | byte; in eeprom_93cx6_readb()
257 eeprom_93cx6_write_bits(eeprom, command, in eeprom_93cx6_readb()
258 PCI_EEPROM_WIDTH_OPCODE + eeprom->width + 1); in eeprom_93cx6_readb()
260 if (has_quirk_extra_read_cycle(eeprom)) { in eeprom_93cx6_readb()
261 eeprom_93cx6_pulse_high(eeprom); in eeprom_93cx6_readb()
262 eeprom_93cx6_pulse_low(eeprom); in eeprom_93cx6_readb()
268 eeprom_93cx6_read_bits(eeprom, &tmp, 8); in eeprom_93cx6_readb()
269 *data = tmp & 0xff; in eeprom_93cx6_readb()
272 * Cleanup eeprom register. in eeprom_93cx6_readb()
274 eeprom_93cx6_cleanup(eeprom); in eeprom_93cx6_readb()
279 * eeprom_93cx6_multireadb - Read multiple bytes from eeprom
280 * @eeprom: Pointer to eeprom structure
282 * @data: target pointer where the information will have to be stored
285 * This function will read all requested bytes from the eeprom,
288 void eeprom_93cx6_multireadb(struct eeprom_93cx6 *eeprom, const u8 byte, in eeprom_93cx6_multireadb() argument
289 u8 *data, const u16 bytes) in eeprom_93cx6_multireadb() argument
294 eeprom_93cx6_readb(eeprom, byte + i, &data[i]); in eeprom_93cx6_multireadb()
299 * eeprom_93cx6_wren - set the write enable state
300 * @eeprom: Pointer to eeprom structure
303 * Set the EEPROM write enable state to either allow or deny
306 void eeprom_93cx6_wren(struct eeprom_93cx6 *eeprom, bool enable) in eeprom_93cx6_wren() argument
311 eeprom_93cx6_startup(eeprom); in eeprom_93cx6_wren()
316 command <<= (eeprom->width - 2); in eeprom_93cx6_wren()
318 eeprom_93cx6_write_bits(eeprom, command, in eeprom_93cx6_wren()
319 PCI_EEPROM_WIDTH_OPCODE + eeprom->width); in eeprom_93cx6_wren()
321 eeprom_93cx6_cleanup(eeprom); in eeprom_93cx6_wren()
326 * eeprom_93cx6_write - write data to the EEPROM
327 * @eeprom: Pointer to eeprom structure
328 * @addr: Address to write data to.
329 * @data: The data to write to address @addr.
331 * Write the @data to the specified @addr in the EEPROM and
338 void eeprom_93cx6_write(struct eeprom_93cx6 *eeprom, u8 addr, u16 data) in eeprom_93cx6_write() argument
344 eeprom_93cx6_startup(eeprom); in eeprom_93cx6_write()
346 command = PCI_EEPROM_WRITE_OPCODE << eeprom->width; in eeprom_93cx6_write()
350 eeprom_93cx6_write_bits(eeprom, command, in eeprom_93cx6_write()
351 PCI_EEPROM_WIDTH_OPCODE + eeprom->width); in eeprom_93cx6_write()
353 /* send data */ in eeprom_93cx6_write()
354 eeprom_93cx6_write_bits(eeprom, data, 16); in eeprom_93cx6_write()
357 eeprom->drive_data = 0; in eeprom_93cx6_write()
358 eeprom->reg_chip_select = 1; in eeprom_93cx6_write()
359 eeprom->register_write(eeprom); in eeprom_93cx6_write()
361 /* wait at-least 250ns to get DO to be the busy signal */ in eeprom_93cx6_write()
367 eeprom->register_read(eeprom); in eeprom_93cx6_write()
369 if (eeprom->reg_data_out) in eeprom_93cx6_write()
374 if (--timeout <= 0) { in eeprom_93cx6_write()
380 eeprom_93cx6_cleanup(eeprom); in eeprom_93cx6_write()