Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: ds1347: changed raw spi calls to register map calls

This patch changes calls of spi read write calls to register map
read and write calls in rtc ds1347

Signed-off-by: Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Raghavendra Ganiga and committed by
Alexandre Belloni
ee85bb5b 68669d55

+54 -43
+1
drivers/rtc/Kconfig
··· 665 665 will be called rtc-ds1343. 666 666 667 667 config RTC_DRV_DS1347 668 + select REGMAP_SPI 668 669 tristate "Dallas/Maxim DS1347" 669 670 help 670 671 If you say yes here you get support for the
+53 -43
drivers/rtc/rtc-ds1347.c
··· 18 18 #include <linux/rtc.h> 19 19 #include <linux/spi/spi.h> 20 20 #include <linux/bcd.h> 21 + #include <linux/regmap.h> 21 22 22 23 /* Registers in ds1347 rtc */ 23 24 ··· 33 32 #define DS1347_STATUS_REG 0x17 34 33 #define DS1347_CLOCK_BURST 0x3F 35 34 36 - static int ds1347_read_reg(struct device *dev, unsigned char address, 37 - unsigned char *data) 38 - { 39 - struct spi_device *spi = to_spi_device(dev); 35 + static const struct regmap_range ds1347_ranges[] = { 36 + { 37 + .range_min = DS1347_SECONDS_REG, 38 + .range_max = DS1347_STATUS_REG, 39 + }, 40 + }; 40 41 41 - *data = address | 0x80; 42 - 43 - return spi_write_then_read(spi, data, 1, data, 1); 44 - } 45 - 46 - static int ds1347_write_reg(struct device *dev, unsigned char address, 47 - unsigned char data) 48 - { 49 - struct spi_device *spi = to_spi_device(dev); 50 - unsigned char buf[2]; 51 - 52 - buf[0] = address & 0x7F; 53 - buf[1] = data; 54 - 55 - return spi_write_then_read(spi, buf, 2, NULL, 0); 56 - } 42 + static const struct regmap_access_table ds1347_access_table = { 43 + .yes_ranges = ds1347_ranges, 44 + .n_yes_ranges = ARRAY_SIZE(ds1347_ranges), 45 + }; 57 46 58 47 static int ds1347_read_time(struct device *dev, struct rtc_time *dt) 59 48 { 60 49 struct spi_device *spi = to_spi_device(dev); 50 + struct regmap *map; 61 51 int err; 62 52 unsigned char buf[8]; 63 53 64 - buf[0] = DS1347_CLOCK_BURST | 0x80; 54 + map = spi_get_drvdata(spi); 65 55 66 - err = spi_write_then_read(spi, buf, 1, buf, 8); 56 + err = regmap_bulk_read(map, DS1347_CLOCK_BURST, buf, 8); 67 57 if (err) 68 58 return err; 69 59 ··· 72 80 static int ds1347_set_time(struct device *dev, struct rtc_time *dt) 73 81 { 74 82 struct spi_device *spi = to_spi_device(dev); 75 - unsigned char buf[9]; 83 + struct regmap *map; 84 + unsigned char buf[8]; 76 85 77 - buf[0] = DS1347_CLOCK_BURST & 0x7F; 78 - buf[1] = bin2bcd(dt->tm_sec); 79 - buf[2] = bin2bcd(dt->tm_min); 80 - buf[3] = (bin2bcd(dt->tm_hour) & 0x3F); 81 - buf[4] = bin2bcd(dt->tm_mday); 82 - buf[5] = bin2bcd(dt->tm_mon + 1); 83 - buf[6] = bin2bcd(dt->tm_wday + 1); 86 + map = spi_get_drvdata(spi); 87 + 88 + buf[0] = bin2bcd(dt->tm_sec); 89 + buf[1] = bin2bcd(dt->tm_min); 90 + buf[2] = (bin2bcd(dt->tm_hour) & 0x3F); 91 + buf[3] = bin2bcd(dt->tm_mday); 92 + buf[4] = bin2bcd(dt->tm_mon + 1); 93 + buf[5] = bin2bcd(dt->tm_wday + 1); 84 94 85 95 /* year in linux is from 1900 i.e in range of 100 86 96 in rtc it is from 00 to 99 */ 87 97 dt->tm_year = dt->tm_year % 100; 88 98 89 - buf[7] = bin2bcd(dt->tm_year); 90 - buf[8] = bin2bcd(0x00); 99 + buf[6] = bin2bcd(dt->tm_year); 100 + buf[7] = bin2bcd(0x00); 91 101 92 102 /* write the rtc settings */ 93 - return spi_write_then_read(spi, buf, 9, NULL, 0); 103 + return regmap_bulk_write(map, DS1347_CLOCK_BURST, buf, 8); 94 104 } 95 105 96 106 static const struct rtc_class_ops ds1347_rtc_ops = { ··· 103 109 static int ds1347_probe(struct spi_device *spi) 104 110 { 105 111 struct rtc_device *rtc; 106 - unsigned char data; 112 + struct regmap_config config; 113 + struct regmap *map; 114 + unsigned int data; 107 115 int res; 116 + 117 + memset(&config, 0, sizeof(config)); 118 + config.reg_bits = 8; 119 + config.val_bits = 8; 120 + config.read_flag_mask = 0x80; 121 + config.max_register = 0x3F; 122 + config.wr_table = &ds1347_access_table; 108 123 109 124 /* spi setup with ds1347 in mode 3 and bits per word as 8 */ 110 125 spi->mode = SPI_MODE_3; 111 126 spi->bits_per_word = 8; 112 127 spi_setup(spi); 113 128 129 + map = devm_regmap_init_spi(spi, &config); 130 + 131 + if (IS_ERR(map)) { 132 + dev_err(&spi->dev, "ds1347 regmap init spi failed\n"); 133 + return PTR_ERR(map); 134 + } 135 + 136 + spi_set_drvdata(spi, map); 137 + 114 138 /* RTC Settings */ 115 - res = ds1347_read_reg(&spi->dev, DS1347_SECONDS_REG, &data); 139 + res = regmap_read(map, DS1347_SECONDS_REG, &data); 116 140 if (res) 117 141 return res; 118 142 119 143 /* Disable the write protect of rtc */ 120 - ds1347_read_reg(&spi->dev, DS1347_CONTROL_REG, &data); 144 + regmap_read(map, DS1347_CONTROL_REG, &data); 121 145 data = data & ~(1<<7); 122 - ds1347_write_reg(&spi->dev, DS1347_CONTROL_REG, data); 146 + regmap_write(map, DS1347_CONTROL_REG, data); 123 147 124 148 /* Enable the oscillator , disable the oscillator stop flag, 125 149 and glitch filter to reduce current consumption */ 126 - ds1347_read_reg(&spi->dev, DS1347_STATUS_REG, &data); 150 + regmap_read(map, DS1347_STATUS_REG, &data); 127 151 data = data & 0x1B; 128 - ds1347_write_reg(&spi->dev, DS1347_STATUS_REG, data); 152 + regmap_write(map, DS1347_STATUS_REG, data); 129 153 130 154 /* display the settings */ 131 - ds1347_read_reg(&spi->dev, DS1347_CONTROL_REG, &data); 155 + regmap_read(map, DS1347_CONTROL_REG, &data); 132 156 dev_info(&spi->dev, "DS1347 RTC CTRL Reg = 0x%02x\n", data); 133 157 134 - ds1347_read_reg(&spi->dev, DS1347_STATUS_REG, &data); 158 + regmap_read(map, DS1347_STATUS_REG, &data); 135 159 dev_info(&spi->dev, "DS1347 RTC Status Reg = 0x%02x\n", data); 136 160 137 161 rtc = devm_rtc_device_register(&spi->dev, "ds1347", ··· 157 145 158 146 if (IS_ERR(rtc)) 159 147 return PTR_ERR(rtc); 160 - 161 - spi_set_drvdata(spi, rtc); 162 148 163 149 return 0; 164 150 }